Getting Started With Node.js and Writting your First Node.js Program

Akshay Kashid
2 min readDec 17, 2019

What is Node.js ?

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications.

How to install Node.js on ubuntu ?

Node.js package is available in the LTS release and the current release on https://nodejs.org.

Lets get started with adding PPA (Personal Package Archives):

As per https://nodejs.org current version is Node.js 13 and LTS (Long Term Support) version is Node.js 12.

Lets add PPA of current version Node.js 13:

sudo apt-get install curlcurl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -sudo apt-get install nodejs

Lets add PPA of current version Node.js 12:

sudo apt-get install curlcurl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -sudo apt-get install nodejs

Check Node.js and NPM version:

For Node.js 13:

Open terminal by pressing Alt + Ctrl + t type the following commands

node -v

13.3.0

npm -v

6.13.1

For Node.js 12:

Open terminal by pressing Alt + Ctrl + t type the following commands

node -v

12.13.1

npm -v

6.13.1

How to install Node.js on windows 10 ?

You can download Current version Node.js 13 or LTS version Node.js 12 from https://nodejs.org/en/download/. You can download and install the Node.js in your system. After complete installation of Node.js in windows you can verify the version of the installed Node.js and NPM in your system.

For Node.js 13:

node -v

13.3.0

npm -v

6.13.1

For Node.js 12:

node -v

12.13.1

npm -v

6.13.1

Wriiting your first Node.js Program:

Open terminal type following commands

mkdir firstnodeprgm

cd firstnodeprgm

touch server.js

Open server.js file in your favourite code editor and write following code

var http = require(‘http’);http.createServer(function (req, res) {res.writeHead(200, {‘Content-Type’: ‘text/plain’});res.end(‘Hello World\n’);}).listen(3000, “127.0.0.1”);console.log(‘Server running at http://127.0.0.1:3000/');

To run the program type in terminal

node server.js

After pressing enter you will see message like:

Server running at http://127.0.0.1:3000/

Open your favourite browser and hit http://127.0.0.1:3000/ you will see Hello World message on webpage.

Conclusion:

Thats it this is your first node.js program and Installation steps to install Node.js on Ubuntu and Windows.

--

--