Node.js installation and configuration for beginners

Hello Friends, In this tutorial we are going to learn about installation and configuration of node.js in our system.

This will be your first “Hello World”  program using node.js.

How to install node.js on ubuntu

I have linux(ubuntu) machine so i ran this command to install node.js in my system

$ sudo apt-get update
$ sudo apt-get install -y nodejs

After installation check node.js installed successfully or not by this command

$ nodejs -v

It’ll display currently installed node version.


If you have window’s machine then you can directly  download node.js exe  and run.
https://nodejs.org/download/

Now time to create your first hello world  program.
create file name app.js in your helloworld directory.

app.js


var http = require('http');

var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Welcome in Hello World");
});

server.listen(5000);

console.log("Server running at http://127.0.0.1:5000/");

And run below command on your terminal to execute your  program and see output on browser and terminal.

$ nodejs app.js

node-beg-1

Hope this tutorial will help you to create your first hello world  program in nodejs. 🙂

If you like this post please don’t forget to subscribe My Public Notebook for more useful stuff.