Why you are using Node.js - BEHIND JAVA

Why you are using Node.js

Share This

Today javascript is a quick growing language. Nowadays javascript includes a lot of great frameworks like nodejs, angularjs, emberjs ....etc those frameworks changes the look of javascript. Previously javascript is only used for UI validation kind of stuff but now you can program server side code using javascript.

NodeJs is a javascript framework which used for server side scripting. NodeJS was introduced by Ryan Dahl in 2009. Nowadays node was the very popular project in GitHub.

What is special in Node.js?

The most important and special feature of Node.js as compared with another server is in Node.js it is possible to create real-time websites with push capability. In node.js this real-time web application with push capability acquired by using web sockets. The advantage of it become in general web applications are using stateless-web based on the stateless request-response paradigm, we finally have web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely. This is in stark contrast to the typical web response paradigm, where the client always initiates communication. Additionally, it’s all based on the open web stack (HTML, CSS, and JS) running over the standard port 80.

Lets go to the internals of Node.js. In highlevel view nodeJS is a comblination of 3 building blocks.

Let's go to these components


libuv is a high-performance multi-platform supported library with a focus on asynchronous I/O. It was primarily developed for use by Node.js and it also using in Luvit, Julia, pyuv and others.

libuv having features like
1. full-featured event loop backed by epoll, kqueue, IOCP, event ports.
2. Asynchronous TCP and UDP sockets
3. Asynchronous DNS resolution
4. Asynchronous file anf file system operations
5. File system events
6. Signal handling
7. IPC with socket sharing using Unix domain sockets or named pipes
8. Thread pool
9. Signal handling
10. High resolution clock
11. Threading and synchronization primitives

V8 Engine

V8 is the JavaScript execution engine built for Google Chrome, open-sourced by Google in 2008. Written in C++, V8 compiles JavaScript source code to native machine code instead of interpreting it in real time.

Node.js contains libuv to handle asynchronous events. V8 provides the run-time for JavaScript. Libuv is an abstraction layer for network and file system functionality on both Windows and POSIX-based systems like Linux, Mac OS X and Unix.

JS and C++

Inside node there is some js and c++ libraries used to manage the basic functionalities of Node.js. The core functionality of Node.js resides in a JavaScript library. The Node.js bindings, written in C++, connect these technologies to each other and to the operating system. Below shows the full stack architecture of a node application

How it works and where it use?

The Node.js applications are works like non-blocking, event-driven I/O to remain lightweight and efficient data flow and processing. The Node.js is not suitable for the applications which using CPU-intensive operations. But Node really shines is in building fast, scalable network applications, as it’s capable of handling a huge number of simultaneous connections with high throughput, which equates to high scalability.

In Traditional web applications, it will create a new thread for each request which result, huge use of RAM. But Node.js operates on a single-thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections

Let's go for a quick calculation. assuming that each thread potentially has an accompanying 2 MB of memory with it, running on a system with 8 GB of RAM puts us at a theoretical maximum of 4000 concurrent connections, plus the cost of context-switching between threads. That’s the scenario you typically deal with in traditional web-serving techniques. By avoiding all that, Node.js achieves scalability levels of over 1M concurrent connections

Also, Node is a single threaded for handling all client requests, it is a potential pitfall of writing Node.js applications because
1. The heavy computation could choke up Node’s single thread and cause problems for all clients (more on this later) as incoming requests would be blocked until said computation was completed.
2. Developers need to be really careful not to allow an exception bubbling up to the core (topmost) Node.js event loop, which will cause the Node.js instance to terminate (effectively crashing the program).

Install Node

I am using windows machine for my development purpose. So in following steps explains how to install node in a windows machine,

1. Download the .msi installer of node from https://nodejs.org/download/
2. Install it on your local machine.
3. Configure the node.js bin path to your System environment properties