Here are our best execution takeaways for working with Node.js:
1. Maintain a strategic distance from synchronous code
By design, Node.js is single strung. To enable a solitary string to deal with numerous simultaneous solicitations, you can never enable the string to look out for a blocking, synchronous, or long running activity.
A recognizing highlight of Node.js is that it was designed and implemented start to finish to be asynchronous. This makes it a great fit for evented applications.
2. Turn off socket pooling
The Node.js HTTP client automatically utilizes socket pooling: as a matter of course, this limits you to 5 sockets for each host.
While the socket reuse may monitor asset development, it will be a serious bottleneck on the off chance that you have to deal with numerous simultaneous solicitations that all need information from a similar host.
In these situations, it’s a smart thought to build maxSockets or totally incapacitate socket pooling:
3. Try not to utilize Node.js for static assets
For static assets, for example, CSS and pictures, utilize a standard web server rather than Node.js. For instance, Linked-In portable uses nginx.
We additionally exploit Content Delivery Networks (CDNs), which duplicate the static assets to servers around the globe.
This has two advantages:
- (1) we diminish stack on our Node.js servers and
- (2) CDNs enable static substance to be conveyed from a server near the client, which lessens dormancy.
4. Render on the client-side
How about we rapidly analyze rendering a page server-side versus client-side. On the off chance that we have Node.js render server-side, we’ll send back a HTML page like this for each demand:
Note that everything on this page, with the exception of the client’s name, is static: that is, it’s indistinguishable for each client and page reload.