Install Node.js - Instructions for Ubuntu, Windows, MacOS ...

[Pages:6]Install Node.js

Node.js installation is a simple task. We just need the right steps. In this tutorial, we shall learn to setup environment for Node.js and the prerequisites to start developing Node.js applications.

JavaScript programming language is used for Node.js Application Development. The source files of Node.js applications have extension of ".js". Any text editor is sufficient to write Node.js code and save it as .js file. To interpret the instructions written in the source .js files, Node.js interpreter is required. The Node.js is available as a binary distribution.

Install Node.js binary distribution

Download the latest binary distribution from []. Based on the Operating System and Architecture, download a suitable package. The size would be less than 20MB.

Following are the latest packages available at the time of writing this tutorials (for x64) :

OS

Package

Linux

node-v8.4.0-linux-x64.tar.gz

MacOS

node-v8.4.0-darwin-x64.tar.gz

W indows node-v8.4.0-win-x64.zip

SunO S

n o d e -v8.4.0-s u n o s -x64.t a r.g z

For linux kernel based OS like Ubuntu/MacOS/SunOS

Once the download is complete, extract the package and include it in the system path variable. Go to the downloaded folder, Open a Terminal from there and execute the following commands.

Unzip the compressed package

~$ tar xvfz nodev8.4.0-linux-x64.tar.gz

~$ tar xvfz node-v8.4.0-linux-x64.tar.gz

Make nodejs directory in /usr/local/ . Replace the file name, if it is different from what you have downloaded.

~$ sudo mkdir -p /usr/loc al/nodejs ~$ sudo mkdir -p /usr/local/nodejs

Move the extracted nodejs package to /usr/local/nodejs/ . Provide user password if asked.

~$ sudo mv nodev8.4.0-linux-x64/* /usr/loc al/nodejs/ ~$ sudo mv node-v8.4.0-linux-x64/* /usr/local/nodejs/

Add the path /usr/local/nodejs/bin to PATH environment variable. Provide user password if asked. Open .bashrc file and append the nodejs' path at the end. To edit .bashrc, open a terminal and run the following command :

~$ sudo nano ~/.bashrc ~$ sudo nano ~/.bashrc

Add the following line at the end of .bashrc file.

.bashrc $ export PAT H=$PAT H:/usr/loc al /nodejs/bin $ export PATH=$PATH:/usr/local/nodejs/bin

Once after adding the line, close the terminal and reopen again. To verify if nodejs path has been added to PATH environment variable, run the following command :

~$ echo $PATH

~$ echo $PATH

For Windows OS, the value echoed back should have /usr/local/nodejs/bin . For installing Node.js on Windows Operating System, double click on the .msi file and follow the prompt step by step. Finishing the prompt should install Node.js with PATH added to the environment variables.

Verify Node.js installation

Using a Text Editor, create a sample file with name verifyNode.js and copy paste the following content to that file.

verifyNode.js console.log("Hi there! This is Node.js!")

console.log("Hi there! This is Node.js!")

And run the following command in Command prompt or Terminal from the directory of verifyNode.js script file.

$ node verifyNode.js Hi there! This is Node.js! $ node verifyNode.js Hi there! This is Node.js!

Run Node.js File

Following is the syntax to run a Node.js file using node command line interface :

~$ node

~$ node

Conclusion

In this Node.js Tutorial, we have learnt to install Node.js on a computer and verify the installation by executing a sample script(.js) file.

Node.js

Node.js Tutorial

Get Started W ith Node.js

Install Node.js Ubuntu Linux Install Node.js Windows Node.js - Basic Example Node.js - Command Line Arguments

Node.js - Modules Node.js - Create a module Node.js - Add new functions to Module Node.js - Override functions of Module Node.js - Callback Function Node.js - forEach

E xp re s s .j s

Express.js Tutorial What is Express.js? Express.js Application Example Install Express.js Express.js Routes Express.js Middleware Express.js Router

Node.js Buffers

Node.js Buffer - Create, Write, Read Node.js Buffer - Length Node.js - Convert JSON to Buffer Node.js - Array to Buffer

Node.js HTTP

Node.js - Create HTTP Web Server Node.js - Redirect URL

Node.js MySQL

Node.js MySQL Node.js MySQL - Connect to MySQL Database Node.js MySQL - SELECT FROM Node.js MySQL - SELECT WHERE Node.js MySQL - ORDER BY Node.js MySQL - INSERT INTO Node.js MySQL - UPDATE Node.js MySQL - DELETE Node.js MySQL - Result Object

Node.js MongoDB

Node.js MongoDB

Node.js MongoDB Node.js - Connect to MongoDB Node.js - Create Database in MongoDB Node.js - Drop Database in MongoDB Node.js - Create Collection in MongoDB Node.js - Delete Collection in MongoDB Node.js - Insert Documents to MongoDB Collection MongoError: failed to connect to server

Node.js Mongoose

Node.js Mongoose Tutorial Node.js Mongoose - Installation Node.js Mongoose - Connect to MongoDB Node.js Mongoose - Define a Model Node.js Mongoose - Insert Single Document to MongoDB Node.js Mongoose - Insert Multiple Documents to MongoDB

Node.js URL

Node.js - Parse URL parameters

Node.js FS (File System)

Node FS Node FS - Read a File Node FS - Create a File Node FS - Write to a File Node FS - Append to a File Node FS - Rename a File Node FS - Delete a File Node FS Extra - Copy a Folder

Node.js JSON

Node.js Parse JSON Node.js Write JSON Object to File

Node.js Error Handling

Node.js Try Catch

Node.js Examples

Node.js Examples Node.js - Handle Get Requests

Node.js Example - Upload files to Node.js server

Useful Resources

Node.js Interview Questions How to Learn Programming

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download