Learning Nodejs for building fast responsive WebSites – Part1.

Few days earlier just surfing heard about nodejs and its rapid fast development and growing popularity.

Node.js is an InfoWorld 2012 Technology of the Year Award Winner.

What is nodejs :
Ya you heard right, Nodejs is server side javascript. Before Nodejs we run the javascript inside the browsers only at client side. But Nodejs makes the javascript run outside the browser, by making use of Google’s V8 VM, the same runtime environment for JavaScript that Google Chrome (browser) uses.

Getting Started:

  1. Install Nodejs on your machine. (mine – windows)
    nodejs windowsinstaller
    Installing it, will install node.exe, npm (node packet manager), and some modules in Program Files folder.
  2. Now open cmd (command prompt) and type
    >node -v // to check the correct installation and it will tell you the version of nodejs installed.
  3. Create new folder with any name. I created node_learning.
    Create a file Hello.js and inside it write console.log("Hello World");
    Thats it save it.
    And run from cmd now.
    >cd node-learning // to go to that file's path
    node_learning>node Hello.js

Create a Web Page with server :

  1. Creating a Server –
  2. Create a file server.js and write code
    var http = require("http"); //instantiate the http module from nodejs module
    http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    }).listen(8888); //port number to listen

    Save this file.

  3. Run it –
  4. Open cmd. Type
    >node server.js
    Nothing will happen only server will start.
    Now Open browser (like mozilla or chrome)
    Open page/url localhost:8888 and the response Hello World will get printed there.
    U can pass html also in place of Hello World text in server.js file
    Thats all. Now you have to explore further.
    For exiting node server in cmd press ctrl + c

Benefits & Conclusion :
There are huge benefits of nodejs. It is very fast and responsive.
Very good for small portfolios, websites and blogs.

Here you have successfully installed nodejs. Build a Hello World static web page.

What Next
In the next part, I will get u make a small website using nodejs with mvvm pattern using express js. Also use of npm would be their