Node.js - reasons to use, pros and cons, best practices!
Sat Oct 11 2014
The same thing makes node server different than other web servers. This article describes what Node.js is, and how it is different and can be one of the most popular and powerful servers in future.
What is Node.js
What node is NOT
Node is not a framework, it's a server.
It's not multi-threaded. It runs in a single thread with callback concept.
What Node is
Node is a open source, cross platform to make real time network applications.
It provides you asynchronous, event driven I/O APIs.
It runs single threaded event based loop, so all executions become non-blocking.
Pros and Cons of Node.js
1. Asynchronous event driven IO helps concurrent request handling.
1. Node.js doesn't provide scalability. One CPU is not going to be enough; the platform provides no ability to scale out to take advantage of the multiple cores commonly present in today's server-class hardware.
2. Dealing with relational database is a pain if you are using Node.
3. Share the same piece of code with both server and client side.
3. Every time using a callback end up with tons of nested callbacks.
4. npm, the Node packaged modules has already become huge, and still growing.
5. Active and vibrant community, with lots of code shared via github, etc.
5. Node.js is not suited for CPU-intensive tasks. It is suited for I/O stuff only (like web servers).
6. You can stream big files.
Why to use Node
This is the strongest reason to select node as your server. Node 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.
var fs = require('fs');
console.log("myFile.txt says:" + data);
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 Node, 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
Node can handle thousands of concurrent connections with a very minimal overhead on a single process.
Easy to learn
Popularity and community
Where Node can be the best solution
Here are few applications or areas where Node.js 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 Node.js 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 for Travel industry where they fetch results from different APIs of different suppliers.
Well, I personally think Ad servers should be the fastest servers. Because, from a 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 Node should be used.
Stock exchange software
Things has to be very much real time in case of stock updates. Node helps us to develop real time web applications.
Today everyone knows the importance of a lightning-fast website and how the speed impacts the conversion rate of a business. Today, everyone wants the site to be a PWA so that the mobile users can have an app-like experience with the website because, for the majority of the merchants, the customers come through mobile devices.
Image sliders or carousels always have increased the UI attraction of websites and they are pretty useful for reflecting the major roles/products too. In case, I am having a website that sells tee-shirts,
Mon Apr 30 2018
Copyright 2022 - www.voidcanvas.com
Authentication using Google's oAuth api with node.js
Thu Mar 10 2016
This is a continuation of my CSS3 loader snippet collection series. I've provided spinning css3 animation loader in the part 1 of this series and here in part 2, I'm providing various square type loading