top of page

Node.js Installation and Print 'Hello World'

Updated: Mar 23, 2021

Before starting node.js one should have a basic knowledge of javascript.


What is Node.js ?


Node.js is a tool for JavaScript framework, it is used for developing server-based applications.

Node.js is an open source server environment. It allows you to run JavaScript on the server. A Node.js app run in a single process, without creating a new thread for every request.


Download Node.js


First of all we have to download node.js from its official site and then we have to install it.


To install node.js you have to follow these steps:


Step 1) Click on the link given below and you can download node.js directly from its official site:

When you click on the link a page like this will open in a new tab. You have to download node.js according to your system requirement like, for Windows operating system you have to click on "Windows Installer".


Step 2) Double click on the downloaded .msi file to start the installation. Click the Run button on the first screen to begin the installation.


Step 3) Click the "Next" button to continue with the installation



Step 4) Click on the box to Accept the license agreement and then click on the Next button.


Step 5) If you have to change the location you can do it from here, by choosing the location where Node.js needs to be installed and then click on the Next button.


Step 6) Accept the default components and click on the Next button.


Step 7) Click the Install button to start the installation.


Step 8) Click the Finish button to complete the installation.




Now, you have successfully installed node.js in your system.



"Hello World" in Node.js


After downloading and installing node.js, now we have to display "Hello World" in a browser.


For this we have to create a file in any text editor and name it as index.js file, and add these lines of code in it:

varhttp = require('http'); http.createServer(function(req, res) {   res.writeHead(200, {'Content-Type':'text/html'}); res.end('Hello World!'); }).listen(8012);

You have to save the file on your computer in: C:\Users\Your Name\index.js



Command Line Interface


Node.js files must be initiated in the "Command Line Interface" program of your computer.

Now you have to open Command Prompt in your system.

For Windows users, press the start button and look for "Command Prompt", or press Windows+R and write "cmd" in the search field and click on OK.



Initiate the Node.js File


The command prompt will look like this:

The file you have created has to be initiated by Node.js before any action can take place.

Start your command line interface, write node index.js and press enter:


Now, your computer works as a server!

Start any internet browser, and type in the address: http://localhost:8012




If you have any queries regarding this blog or need any help you can contact us on: contact@codersarts.com


Comments


bottom of page