Node.js installation guide for beginners: A blog about Node js installation and how to work with Node.js

 

Node.js is a lightweight, open source and cross-platform JavaScript run-time environment that executes JavaScript code outside the browser. It is developed by Joyent, Inc., a company which also offers cloud services based on Node.js.

Node.js runs on Windows, Mac OS X, Linux and BSD operating systems and can be downloaded from their website: https://nodejs.org/en/.

There are two ways to install Node.js:

Using the installer from their website (recommended)

Building from source code

Run the installer, follow the onscreen instructions until you get an option to choose components to install in Node JS package manager (NPM).

Check your node js version by running the following commands :

node -v

To check npm version run the command below :

npm -v

 

Steps to setup node js app first time :-

1. First Make a directory using mkdir command

mkdir nodejsproject

2. Open that directory by running the cd command

cd nodejsfolder

3. Create node js repository 

npm init

4. Install required libraries Like express

npm i express

5. Make a server.js file and add the following code

var http = require("http");

http.createServer(function (request, response) {
   // Send the HTTP header 
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   
   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(3000);

// Console will print the message
console.log('Server running at http://127.0.0.1:3000/');

6.  Finally run the node js command to run node on server

node server.js

Open your browser and paste this URL in new tab

http://127.0.0.1:3000/