Considerations that would be helpful in deciding whether Node JS is a suitable platform for your application.
The factors are taken into consideration when deciding whether Node.js can be used for any application are-
- Node.js can be used in applications that need to keep a persistent connection from the browser and back to the server. With the ‘long polling’ technique user can write an application that can send updates in real time. And one would wonder if this would create a great deal of load on the server as each active client can eat up the server process. But with Node.js the server need not maintain separate threads for each open connections nor would it utilize any system resource to serve many clients. This concept suits a browser-based chat application very well. So one can question if Ruby and Python can’t do it that way? Yes they can, but node.js can do it better.
- Apart from chat applications, Node.js is also suitable for implementing online, multi-player games, and collaboration tools where work was done by one connected user should be propagated to other connected users immediately, in real time. Also valuable in applications that demand the tracking of website visitors whilst gathering real-time user statistics which in turn is used to enhance business based on data gathered in real time. Web sockets is used for this real-time, two-way communication channels between the client and the server with which the server can push data to the client as easily as the client pushes data to the server. Socket.io is the most popular web socket libraries used, which makes collaborative web applications simple.
- Node.js is secure, easy to learn, can work with heavy traffic and handle millions of requests at a given time which means that one can build scalable applications with Node.js.
- With an event-driven architecture and a non-blocking I/O API, Node.js optimizes an application’s throughput and scalability. Node.js uses an event loop, instead of processes or threads, to scale. Callbacks are set, and the server enters the event loop when there are no further callbacks to be performed.
- With many server-side programming languages, concurrency is difficult which in turn leads to poor performance. Node.js is a single-threaded event-driven system which is fast when handling many requests at once. For any concurrent request, an event is registered with its callback. The server will not wait for the response of a particular request but will move ahead to serve the next request. Whenever any request completes, it triggers its corresponding event and executes the registered callback to completion without being interrupted. So with Node, there is no waiting. Also, there is no memory consumption for serving the REST API as is in multi-threading.
- A huge list of Node modules can be found at the NPM website and anyone can publish their own module that will be stored in the repository. A large community is also available for help and support in case of any roadblocks. Users can also get help from experienced users who resolve issues within a few hours.
Some famous Node.js users are PayPal, Yahoo, LinkedIn, eBay, Netflix, Walmart and many more.
When shouldn’t we consider Node.js?
- When an application is dependent on heavy CPU consuming algorithms, then one might have to think other than Node because any CPU intensive operation cancels all the benefits Node offers with its event-driven, non-blocking I/O model.
- Secondly, when an application being developed requires relational database access… Relational DB tools for Node.js are still in their primitive stages and so are not so great to work with. But the option could be to still use Node as the outer tier while keeping Rails at the back-end as it has easy access to a relational DB. Other choice would be to use a NoSQL DB like MongoDB.
- One might end up using too many nested callbacks. This is called Callback-hell! One solution would be for developers to understand promises in node.js.
- If the most part of your application would be rendering HTML out of simple database retrieval/updates, then using node.js may not have noticeable benefits.
With more factors in the affirmative, it is no wonder that Node.js is growing rapidly in the development community.