Node JS Tutorial 1 — Creating the first app with Node JS

Dhevendhiran M
1 min readSep 19, 2018

--

Hello all,

This is Node JS tutorial series. If you are looking to learn Node JS and its stuff. This will be a Kickstarter for you. Have a look into this series to get a deep dive into Node.

In this story, I am going to create a Node JS server and run it on a browser. Simple, right? Let’s start.

Download and Install Node JS

Download the Node JS package suitable for your system configuration from here. Install it as usual.

Server Creation

Open your favorite text editor and create a file named server.js and copy the below code.

server.js

//initializing the http server
var http = require('http');
//onRequest function to create content for html page
function onRequest(request, response) {

//specifying content type
response.writeHead(200, {'Content-Type': 'text/plain'});

//text to print in the page
response.write('Hello World');

response.end();
}
//create server on port 8000
http.createServer(onRequest).listen(8000);

Save the file and open the particular folder in terminal and type

$node server.js

Then open a browser and type localhost:8000. You can see the text Hello World. That’s it. The server is running now.

In the next story let’s discuss connecting the client side javascript code with this server.js. Stay tuned.

--

--

Dhevendhiran M

Software Development Engineer @Altradimension Technologies