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

// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Welcome in Hello World");
});
// Listen on port 5000
server.listen(5000);
// Set confirmation message with hostname and port
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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.