what is Node js

Node js is open source, server-side javascript language which built on the top of google chrome v8 javascript engine. it uses event-driven, nonblocking IO model that makes it’s more lightweight and efficient and as unlike Apache is multi-thread HTTP-server it means every HTTP request to Apache server, it creates a separate thread and in the case of node js, it handles all HTTP request in single thread asynchronously.

Local Host HTTP Server

Before reading this you need to know basics of  JavaScript

Nod js has built-in HTTP  module (module is same as library) to including that we use require method

var http = require('http');

HTTP module can create HTTP server which will listen for connection (request from the client) on given port and send a response  back to the client.

var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the server object listens on port 8080

This image will clear your all doubt

so the above code does same as shown in the figure.

In manner to run the node app (HTTP server)

node index.js

index.js is your file name, you can replace with your file name and your local machine will listen for HTTP connection.

Categories: backendNode.js


Android Developer Intern

Related Posts


How to schedule functions in Google AppScipts?

I was assigned a task of creating an application that could be scheduled periodically in Google AppScripts.  This application should appear as a Modal Window in a spreadsheet whenever the user requests for it from Read more…


Getting List ID for Trello API

Getting List ID for Trello API So the MangoBlogger onboarding task required me to add a card to my trello board using the Google App Script, https://script.google.com/ But after some fiddling around with the Trello Read more…


Why startups should consider Node.js?

  A startup that succeeds can make a lot of money for themselves and their investors. However—as the common VC proverb goes—for every one startup that hits it big, another nine will fail. So, of course, Read more…