Any tips/tricks/suggestions? I heard many good things about Node.js and finally gave it a try. I would like to know about the tricks that are known to improve performance of a Node.js web app.

Write your answer…

5 answers

Here are a few things that worked for me :

  1. Use a library like async to run tasks in parallel. Don't run functions in series if they don't depend on each other. Try to parallelise tasks as much as possible.

  2. Don't use the sync version of many functions unless you really really need to. For example, fs module exposes two functions for reading files : readFile and readFileSync. As Node.js is single threaded and event driven by nature, synchronous operations can block the main thread which in turn may affect the performance of your app.

  3. Use Redis/Memcached for caching content that doesn't change frequently. This will dramatically improve your performance.

  4. Turn on Gzip compression. Today most of the browsers support gzip and there is no reason not to use it. Use a middleware like compression to enable gzip in your Express app.

  5. Utilise client side rendering. It's even better if you support both client and server side rendering. Use a library like React for building isomorphic apps.

  6. Don't store too much data in session (e.g. just store userId for logged-in users) and use Redis/Mongo store for storing session data.

  7. Use nginx as a reverse proxy. Let it serve static resources and dispatch other requests to your Node.js app.

Here is a detailed article that I wrote on SitePoint some days back. It explains all of the points in detail.

Hashnode is building a friendly and inclusive dev community. Come jump on the bandwagon!

  • 💬 A beginner friendly place

  • 🧠 Stay in the loop and grow your knowledge

  • 🍕 >500K developers share programming wisdom here

  • ❤️ Support the growing dev community!

Register ( 500k+ developers strong 👊)

Upgrade to Node.js v0.12. It has undergone so many performance improvements. Functions like setImmediate() and process.nextTick() are now faster than they used to be. See :

Also you should always use cluster module for production Node.js apps. It forks your parent Node.js process to spawn child/worker processes and uses round robin algorithm (v0.12) to distribute incoming connections evenly among the workers. So, if you are using a multi core VPS to deploy your app you should take advantage of cluster.

I created (with others) an Npmjs module called multi-level-cache that manages local and remote caches for node. The idea is that it looks in its in-memory local cache for the data (which might have expired) and then at a remote cache (which also might have expired) before looking at the DB. You can create an efficient caching hierarchy with this type of architecture to speed up your apps. I recently did Tutuapp with these techniques.

Actually this is one of the most exciting games. And the site also has many different types of games you can play and feel. Thank you very much for visiting my website and wish you success. Thank you so much! |=> bloons tower defense 5 super smash flash 2