Node.js – An Introduction

Node.js is a server side platform built on Google Chrome’s JavaScript Engine called the V8 Engine. Node.js was developed by Ryan Dahl in 2009 and its latest version is v0.10.36. It is used to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications.

The definition of Node.js as supplied by its official documentation is as follows –Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.

Node.js also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.

Put mathematically;Node.js = Runtime Environment + Javascript Library

Features of Node.js

Following are some of the important features that make Node.js the first choice of software architects.• Asynchronous and Event Driven: All APIs of Node.js library are asynchronous that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

Let’s elaborate a bit more on this point.

Event-based: a server will constantly be getting requests (at different urls, on different ports) that need to be responded to in different ways when those events take place

Asynchronous: in dealing with a request, a server will need to load other data (from a file, a database, another server like Twitter), and you don’t want your entire server to just lock up while it waits for that external service (we call this I/O for “Input/Output”) to finish. For a typical web request, the majority of time will be spent waiting on I/O.

The synchronous code runs on top of an asynchronous web server (Apache, Rack, WSGI) that creates a synchronous ”thread” to run your Ruby/Python/PHP code. If another request comes in while that first thread is still processing, the web server creates a new thread. Unfortunately, those threads are resource-intensive which means you can only create a limited number of them (based on how powerful your server is). If all your threads are in-use, a new request will have to wait until a previous request is finished and the thread becomes available again.

In case of Node.js instead of adding web-browser functions/extensions to the Core Javascript language, Node.js adds server functions/extensions e.g. managing http requests, filesystem operations, talking to databases, etc. While Node.js runs everything on one single “thread”, because Javascript is event-based/asynchronous we can serve hundreds (if not thousands) of simultaneous requests at once because Node.js doesn’t have to freeze/lock for the “I/O” (“In/Out” e.g. database, filesystem, external-service) processes to finish… Node.js can just answer another request (and another) while waiting for first request’s (and subsequent requests’) I/O process to complete, then come back to it and do the next step in responding to the request. Node.js is a master delegator.

• Lightning Fast: Being built on Google Chrome’s V8 JavaScript Engine, Node.js library is very fast in code execution.

• Single Threaded but Highly Scalable: Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.

• No Buffering: Node.js applications never buffer any data. These applications simply output the data in chunks.

• License: Node.js is released under the MIT license.

Concepts
The following diagram depicts some important parts of Node.js

Where to Use Node.js
Following are the areas where Node.js is proving itself as a perfect technology partner.
• I/O bound Applications
• Data Streaming Applications
• Data Intensive Real time Applications (DIRT)
• JSON APIs based Applications
• Single Page Applications

Where Not to Use Node.js
It is not advisable to use Node.js for CPU intensive applications.

he next most logical question is, who uses Node.js ? Well to name a few it is being used by eBay, General Electric, GoDaddy, Microsoft, PayPal, Uber, Wikipins, Yahoo! and Yammer. To get a comprehensive list of node.js users CLICK HERE