19 Dec 2013

Setup your workstation for Node.js / Getting started with Node.js

12/19/2013

First things first, Install Node.js from Node.js website. The installer should install the Chrome's JavaScript runtime along with Node.js framework on your system and even setup environment variables.

How to check if node.js is installed and ready to be used ?
Go to the command prompt and write command "node" , it should get recognized a ">" line prompt should appear, as shown below







Lets now make out first example to understand Node.js. Lets take a problem statement where we want to create a web application which has a single page, when we hit that page from the browser, it should say "Hello World".

Lets now create a file hello.js, write the below code in the hello.js file

var http = require('http');
http.createServer(function (req, res) {
res.end("Hello World");
}).listen(8888);
console.log('Server running at http://127.0.0.1:8888/');

To run the application, go to the command prompt and type "node hello.js


Now go to your browser and hit the url 'http://127.0.0.1:8888/', this would simply show you a web page with "Hello world" as simple response.

Thats it, your first node.js application is ready.



Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 NimbleGeek. All rights resevered. Designed by Templateism

Back To Top