What is Node JS?
Node JS is developed by Ryan Dahl in 2009 and it is an open source, cross platform java script runtime environment for running server side applications.
Node JS is used to build I/O intensive web applications, highly scalable web applications, data intensive web applications and real time applications.
Node is great for prototyping and agile development. By using node js can build super fast and highly scalable services.
Node JS is used by large companies such as PayPal, Netflix, Uber and etc.
Since node js using java script source code it is more cleaner and consistent.
Node is available with largest echo system of open source libraries and Node is not a programming language.
Before node java script is used only to build applications that run inside the browser. So every browser have different java script engine that convert java script code in to machine code. As an example Firefox uses SpiderMonkey and chrome uses v8 as the java script engine. Due to this reason java script code can be behave differently in different browsers.
However the founder of the node discovered a way to execute java script code outside of the browser. He took the fastest java script engine chrome v8 engine and embedded it in a C++ program and call that program as ‘Node’. Therefore Node is a runtime environment with a java script code. Node is a program consist of v8 java script engine that can execute java script code and have additional modules that gives capabilities which are not available inside browsers.
How does Node work?
Node is non blocking and have an asynchronous nature. In node there is only one thread to handle all the requests. When this single thread have to do some I/O operations the thread does not have to wait until the I/O operation finishes. During the I/O operations the thread can serve another client request. After finishing the I/O operation the I/O operation put the message in the event loop. Node is continuously monitoring the event loop. When node find an event in the loop it will take that event and start processing that event. This type of architecture of node is ideal to build I/O intensive applications.
Using node can serve more client without adding additional hardware. This is the reason that Node applications are highly scalable.
Even though node is ideal for I/O intensive applications it should not use for CPU intensive applications. Because CPU intensive applications there are lots of calculations should be done by CPU and have few I/O operations. Because node is single threaded while finishing one particular clients request other clients have to wait.
Use Cases of Node JS
I/O intensive web applications
Data intensive real time applications
JSON based API applications
Data Streaming applications
Single page applications
Advantages and Disadvantages of Node JS
Node JS applications are easy to scale horizontally and vertically.
Single programming language. Node JS developers can write the front-end of the application as well as the back-end of the application in java script using runtime environment. So, developers does not have to use any other server side programming language.
High performance due to java script v8 engine convert java script code directly into machine code.
Node JS is Extensible. For the client request node js can be customize and can be extend.
Node JS have supportive, active and large community of developers which contribute for the advancement of node js.
Node JS non blocking I/O systems help to handle requests simultaneously.
Node JS APl changes more frequently which leads new API to have number of incompatible changes.
Asynchronous programming model is more difficult that synchronous programming.
Node JS is not appropriate for computational intensive functions.