Here we are explaining about Nods Js features and how to create your first application using Node JS.
Node.js is a popular open source platform . It work in run-time enviornment for developing server-side web applications. Ryan Dah developed Node.js in 2009 and its latest version is v0.10.36.
It operate on single thread, using non-blocking input- output calls. Application written in Node.js is using JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.
A huge library of various JavaScript modules is provided by Node.js which help in simplifying the development of web applications.
Node.js = Runtime Environment + JavaScript Library
Features:
1) Asynchronous and Event Driven
2) Single threaded but highly scalable
3) Very Fast Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution.
How To Install Node.js on Ubuntu 14
1) Before installing node js we need to run following command as this updates the local repository information.
sudo apt-get update
2) Install the Node.js package using following command.
sudo apt-get install nodejs
3) Node Package manager : This will allow to easily install modules and packages to use with Node.js.
sudo apt-get install npm
Verify the Installation:
Create a file test.js and write some message for testing
console.log("Testing node JS")
Then execute the following file from Command line
nodejs test.js
If the installation was correct then it will show the following output:
Testing node JS:
Create First Application:
1) Create a new file testnode.js
2) Write the following code in file.
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response "Welcome Node JS" to the browser
response.end('Welcome Node JS');
}).listen(8082);
Create the object of http module and store in a variable and then we bind it with a port using listen method .
3) Start the node server.
nodejs testnode.js
4) It will send the output to browser
http://localhost:8082/testnode.js
0 Comment(s)