find and solve || findandsolve.com
Please wait.....

What is Node.js

What is Node.js

Node.js Introduction

Node.js is an open source server environment which is free.Node.js runs on various platforms lik as Windows, Linux, Unix, Mac OS X, etc and use JavaScript on the server.This is a server-side platform built on Google Chrome's JavaScript Engine (V8 Engine) and developed by Ryan Dahl in 2009 and its latest version is v0.10.36.Node.js uses asynchronous programming.This is also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.

Download Node.js from  https://nodejs.org

Node.js = Runtime Environment + JavaScript Library

Some Features of Node.js

Some features are must important that make Node.js the first choice of software architects.

  1. Asynchronous and Event Driven
  2. Very Fast
  3. Single Threaded but Highly Scalable
  4. No Buffering
  5. License 

Used Node js in

  1. I/O bound Applications
  2. Data Streaming Applications
  3. Data Intensive Real-time Applications (DIRT)
  4. JSON APIs based Applications
  5. SPA(Single Page Applications)

Getting Started

The main require directive to load the http module and store the returned HTTP instance into an http variable as give below.

Step 1.

var http = require("http");

Step 2.

We are already the created http instance and call http.createServer() method to create a server instance and then we bind it at port 1111 using the listen method associated with the server instance

http.createServer(function (request, response) {
   // Send the HTTP header
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(1111);
// Console will print the message
console.log('Server running at http://27.34.69.69:1111/');

In the given above code is enough to create an HTTP server which listens, i.e., waits for a request over 1111 port on the local machine.

Step 3

Let's put step 1 and 2 together in a file called demo.js and start our HTTP server as a given below

var http = require("http");
http.createServer(function (request, response) {
   // Send the HTTP header
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(1111);
// Console will print the message
console.log('Server running at http://27.34.69.69:1111/');

Now execute the demo.js to start the server as given below.

$ node main.js


Selena  Kandakar

Selena Kandakar

I like working on projects with a team that cares about creating beautiful and usable interfaces.

Comments



Report Response