Part 3 | Why we should use nodeJS
Hello tech-peers. We are back and today close our blog series by knowing more on why to use nodeJS and what could be some of its best applications. Enjoy the piece!
This is the strongest reason to select node as your server. nodeJS is completely event driven and majority of the code runs basing on callbacks. This approach helps the application not to pause or sleep, but to become available for other requests. Let’s explain this with an example.
Suppose the program will read a .txt file and print the content as output.
If you notice the code, you will find in php, in line no#3, it will start reading the file and before finishing up reading the file it can’t do anything else. That means php blocks the execution there. Whereas in case of nodeJS, in line no#3 it starts reading the file and assigns a callback to it, and proceeds to the next line. It continues executing the other parts of the program and whenever the “fs” finished reading the myFile.txt, the callback will be called to process necessary statements.
Concurrent request handling
nodeJS is architected to handle concurrent requests.
Same code can be shared between server and client, etc.
Easy to learn
Java Script is the most popular language according to the StackOverflow (http://stackoverflow.com/insights/survey/2016 ) This is because it is easy to learn and get started with.
Popularity and community
Where nodeJS can be the best solution
Web Socket Server
The non-blocking architecture of node makes it the best-suited solution for socket server applications or broadcasting like applications. Chat servers can become more efficient and real time using nodeJS as their base.
Fast file upload client
With node you can upload multiple files at a time. That means it is possible that a part of file1 and another part of file2 is in the server at a given point of time. This approach makes file uploading dramatically fast.
As node deals with callback concept, it can easily be used for streaming data flow. It can be really useful when data is coming from different sources
Well, I personally think Ad servers should be the fastest servers. Because, from an advertiser’s point of view, if I can load the ads before all the contents of the page is loaded, I may catch the visitor. Another is if my ads load slower, the visitor might navigate to somewhere else. So ad servers really need to be fast and thus nodeJS should be used.
Stock exchange software
Things have to be very much real time in case of stock updates. Node helps us to develop real time web applications.
nodeJS clustered server
What is a cluster in general? A cluster is a set of loosely or tightly connected compute machines or resources (called “nodes”) that communicate with each other and share work to solve a single purpose. It can be viewed as a single system.
Hope you’ve enjoyed and benefited from our three-part blog series on nodeJS. Its been a pleasure sharing it with you – and we’d love to hear your thoughts on it. Drop us a comment below! Bye