install node js hello world node js example for beginners

Hi Guys, Welcome to Proto Coders Point, In this Programmer Blog post we will learn About What is Node.js and Why is Node js used for? and even we will check how to install NODE.JS on Windows System.

What is Node.js?

Node.js is basically an Open-Source Scripting Language, It is and JavaScript runtime Environment that executes JS codes outside a browser also.

The Node js will help the Back-End Developer use javascript to write server-side script to produce dynamic web page and fetch data from database before web page is sent to user’s browers.

In Short Node.js is and Open Source server environment which is completely free to used and Node.js is very speed and easily compatible on various OS platforms (Windows, Linus , Unix, Mac OS any many more)

Why NodeJS is Famous?

By using Simple JavaScript, we cannot get access to files system from browser but sometimes there is a situation, where we need to be able to read data from local file system sinse this is not possible by using Javascript.

In this sense we need something that we can use to interact directly with the computer file system, that’s what exactly what node.js allows us to do.

Node.js allows us to take javascript out of the browser by allowing us to interact directly with the computer data source.

Thus not we can access system files, Therefore by using Node.js we can also create a desktop application and Atom Editor is the best example that is built using Node.js.

Then, Now you can write javascript code not just for browser but also to make use of hardware component or file system.

Why node.js?

Well, node.js can be run on your own computer or somebody else computer rather say it you can run server script using Node.js on server computer.

How to Install Node.js on Windows?

Installation Steps

  1. Download the Windows installer from the Nodes.js® web site
  2. Choose the LTS version that’s shown on the left. 
  3. Run the installer (the .msi file you downloaded in the previous step.)
  4. Follow the prompts in the installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).

    node js installation
    node js installation

5. Restart your computer. You won’t be able to run Node.js® until you restart your computer.

6. Confirm that Node has been installed successfully on your computer by opening a Hyper terminal and typing in the commands node --version

how to check nodejs version

You should see the version of node you just installed. So you can see my pc is been install with NodeJS version 12.17.0

Getting Started with NodeJS

Once Nodejs is been Installed successfully in your OS, Let’s use write a node script that will simply display ” HelloWorld” on the Browser.

Create a folder on your Desktop named “nodejs” under that folder Create a .js file named “helloworld.js”, and add the following code:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/h1'});
    res.end("Hello World! Welcome to Proto Coders Point");
}).listen(8080);

console.log(" Server Running at : http://localhost:8080/");

Save the file.

Then Open Comment Prompt and run the below command

1. moving inside folder.

C:\Users\rajat>cd Desktop

C:\Users\rajat\Desktop>cd nodejs2

2. run the script using node cmd

C:\Users\rajat\Desktop\nodejs2>node helloworld.js

 

Then,  your computer works as a server of helloworld.js file

If anyone tries to access your computer on port 8080, they will get a “Hello World!” message in return!

Start your internet browser, and type in the address: http://localhost:8080

how to run nodejs file in cmd prompt

Result on the browser

 

1 Comment