How to install and configure Node.js


How to install and configure Node.js

How to install and configure Node.js Server on Windows

In the way of learning MERN stack, we will install Node.js and configure the server on windows. Here is a question arise in our mind, in MERN (MongoDB,Express.js, React.js, Node.js) stack, why Node.js is required to install? We must understand Node.js is JavaScript server platform, where all script will be run on that platform. Without Node.js Server, any script of Express.js, React.js and Node.js are cannot be executed and connecting with MongoDB database not be possible.

Like in the case of LAMP, XAMPP or WAMP, it create a server platform where PHP scripts are executed and MySQL databases are connected with the application. Same, in the Node.js server platform, JavaScript executed and MongoDB databases are connected with the React.js application. One special thing in Node.js Server, we can create dynamic server, multiple server at same time. We will learn this interesting thing in some easy following steps-

Download the Node.js installer and install in the system.

Also know that what is Node.js

  1. We are installing the Node.js installer from the official Node.js website- Click here and download (LTS - Recommended For Most Users) the .msi file according to our system environment (32-bit & 64-bit). Just an .msi installer will be downloaded on our system.

  2. Node.js Installer
  3. After Downloading .msi file, we have to start installation normally on double click on that.

  4. Also read What is MERN Stack

  5. In the installation, a simple traditional installation process wizard with Click on "Next" button, and at last "Finish" button to complete the installation.

  6. After completing Installation, you can also check for Node.js has been properly installed or not, through the following command at CLI (Command Line Interface).

  7. When you type this command at CLI prompt, it will be display the version of Node.js., if Node.js is properly installed, otherwise displayed error.
     node -v 
  8. Node.js check command at CLI (Command Line Interface)

    If your command prompt display the version of Node.js, feel happy that Node.js installed successfully in your system.

Create a server and "A sample program of Node.js"

  1. Create a folder at any directory. For example - create directory at C:\ drive with name "node_program"
  2. Open a Notepad++ or any text editor and create a hello.js file with following code and save it.
  3. var http = require('http');
    http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end("Hello World! 
    I am Bhagwan Babu"); }).listen(3000);

    Let us understand ... What is in the code? How is the code work?

    In the 1st line of the code require function read JavaScript file(http), execute and return an object.  Its also means application has access to the HTTP module, and is able to create a server.

    In the 2nd line of code, server creating function is called, whenever a request is made to our server application, and response to the client, both are as argument in function.

    In 3rd & 4th lines, when server received a request, writeHead function is used to send header data to the client, we are asking our function to return a “Hello World” response to the client, and the end function will close the connection to the client.

    At last, listen(3000), We are giving a port no. 3000 for client requests. You can give different port no. like, 8080, 3001, 3002, etc. it is necessary that port is not used.

    Now execute the code.

  4. Open the directory where hello.js file saved and execute the following command
  5.  node hello.js
    execute command for node.js file

    After the above command executed, if nothing happen, please stay, don't disappoint.

  6. Open any browser like Google Chrome and type the address in url "localhost:[port_no]"-

  7. Output of Node.js Hello World Code
  8. Close the server by pressing "Ctrl+C" in command window

  9. Close the Node.js Server


    Here we learnt, how to download Node.js Downloader and install in our system. We also learnt how to check Node.js is properly installed or not in our system. After that we learnt first sample program in Node.js, how to creating server and execute the node.js code in browser.

    In next session we will learn more about MERN technology one-by-one...Thanking you for reading

0 comment(s)

Leave a Comment