---
title: "Discussion on \"10 things you shouldn't do while running Node.js in production\" | Hashnode"
description: "Discussion on \"10 things you shouldn't do while running Node.js in production\". At Hashnode we heavily use Node.js. I am a big fan of it and have learned a lot of things while running Hashnode. When I hang out with other developers, I notice that many people don't utilise Node to its full potential and do certain things the wron..."
url: "https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [10 things you shouldn't do while running Node.js in production](https://hashnode.com/post/10-things-you-shouldnt-do-while-running-nodejs-in-production?utm_source=hashnode&utm_medium=feed)

At Hashnode we heavily use Node.js. I am a big fan of it and have learned a lot of things while running Hashnode. When I hang out with other developers, I notice that many people don't utilise Node to its full potential and do certain things the wron...

Aug 25, 2016 · hashnode.com  
Updated Dec 25, 2016  
Read the article

-   [#nodejs](https://hashnode.com/tag/nodejs)

## Written by

[Sandeep Panda](https://hashnode.com/@sandeep)

@sandeep · Bangalore

  
[View profile](https://hashnode.com/@sandeep)

co-founder, Hashnode

I am the Co-Founder of Hashnode. I write (about) code and keep interest in Venture Funding and startups. Feel free to contact me at sandeep@hashnode.com.

## Responses 13

Markdown supported · ⌘↵ to post

[ziedch](https://hashnode.com/@ziedch)

[Mar 19, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/5ab02dc486ffd60e7b969303)

can you explain more about Maintaining global states inside the Node web processes. If i _MUST NOT_ store session id in memory then what to do instead ?

[Stefan Müller](https://hashnode.com/@SM)

[Jul 20, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/59706a2f107fab2733afe15c)

I would like to add the following topics as what you shouldn't do in production:

-   Serve static assets not minified and gzip'ed (see grunt)
-   Disallow local caching for those static assets
-   Keep access logging enabled
-   Store uploaded files on disk folders instead of a virtual file system like GridFS

[Abhishek Sharma](https://hashnode.com/@0xabhishek)

[Jan 30, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/59706a2f107fab2733afe15c#reply-5a70bc4fd3e3e6ca6266612a)

Why use gridfFS if the file is not meant to be streamed back to the client and only used for processing? Just curious. We at our startup take in a video and generate meta data off it with AI. Summary, questions, chapters etc. (Everything patented) We need to only process the video and not serve it back. Even if we do need to stream it, I'm sure grid FS won't do any justice. Or would it?

[Todd](https://hashnode.com/@theonlyrealtodd)

[Jul 11, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/596467fb9e47db7654a77c17)

Thanks for this. I just recently launched a node website and this will come in handy!

[s710](https://hashnode.com/@s710)

[May 12, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/5915cc72f32035441997ace1)

Also some thoughts from here:

> Node.js is single threaded in nature

This is not entirely true, since the underlying v8 engine _of course_ uses multiple threads. By default, these are 4, but can be increased. Threading is used for any non-blocking I/O (that is, file I/O, network I/O). And as you already suggested, not to do heavy lifting (=CPU intensive work), it means that node.js/v8 is already very well prepared for parallel processing and utilizing multiple CPUs/cores. Therefore, I would disagree that the clustering module is a _must_.

> Not using Node.js Cluster

You already suggested nginx as reverse proxy, it should be mentioned that nginx can also be very well used as a load balancer for node.js applications. For a comparison see this link: [keithcirkel.co.uk/load-balancing-node-js](https://www.keithcirkel.co.uk/load-balancing-node-js/)

Especially its capability to dispatch requests to node.js processes according to their current number of pending requests can probably be superior to the common round-robin approach.

[sai krishna](https://hashnode.com/@sai451)

[Jun 1, 2019](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/5915cc72f32035441997ace1#reply-5cf2b27fe46ca4a542122f1f)

Does anyone faced problems with CPU spikes to 100% and when I reload it drops and gradually increases again. I am using pm2 cluster mode

[Christian Dimas](https://hashnode.com/@christiandimas)

[Apr 23, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/58fcb943d23bc81fe858f330)

Hi, sorry to bump up on an old post. But this shows up when I search for clustering in PM2.

I'm still new in nodejs. My question is, does it really needed in all production use case?

Yes I'm aware that it improves the speed a lot, but in my use case, I use chokidar to watch a directory, and then fork a child\_process for uploading it to S3 every time new file added.

When I tried to run PM2 in cluster mode, and it does the same thing twice. How can I improve the app performance without getting this?

[Munif Tanjim](https://hashnode.com/@MunifTanjim)

[Oct 16, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/58fcb943d23bc81fe858f330#reply-5bc60f64d381428c637527b3)

It's a little late 😅 but,

Extract chokidar in a separate process so that you don't have to run it in the cluster.

[Won yong, Jin (Brian)](https://hashnode.com/@wjin)

[Feb 14, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/58a378f6c88a26aff758545b)

hey nice article. i am a junior node developer and i don't know any of the things you spoke of above. what references should i search for to start learning this from the beginning? im kind of clueless on where to start as you went over a lot of things. i created say a social media blog / video app with user auth using passport and tokens.

you mentioned using clusters? i guess all of this is in devops department? what do you suggest or where do you suggest i start to learn this stuff it all feels really scattered how can i lower my learning time and rate for this stuff?

[Neil](https://hashnode.com/@neilrogers)

[Aug 30, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c4d25c4d46e2df2e64f867)

**Lack of Monitoring**

can you suggest a tool to send/log these errors or does the pm2 monitoring tool do this?

[Daniel Lobo](https://hashnode.com/@danlobo)

[Nov 25, 2017](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c4d25c4d46e2df2e64f867#reply-5a19a76dccec2be146977e34)

We use graylog to centralize logs, it's a nice tool to have.

[Abhishek Sharma](https://hashnode.com/@0xabhishek)

[Jan 30, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c4d25c4d46e2df2e64f867#reply-5a70bb82d3e3e6ca62666126)

ELK !! Like seriously?

[cedric simon](https://hashnode.com/@Simonced)

[Sep 30, 2019](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c4d25c4d46e2df2e64f867#reply-5d91c9853370fc455f1450c0)

PM2 has output and error logs for each process.

Edit: sorry, I revived a 4y old topic. For some reason it was in my feed today...

[Cuy Chactado](https://hashnode.com/@Ljq)

[Aug 28, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c2bcca387df20e0b9f95a5)

Some good stuff but I don't use the cluster module when running inside docker

[akhilesh gupta](https://hashnode.com/@iiakhilesh)

[Aug 27, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c138c093309a25047c6398)

Dockers is also worth mentioning

[Saravanan Ramupillai](https://hashnode.com/@saravanan10393)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c04ae2f296bc7fca298281)

HI Nice article Found very useful, If i use the cluster then how socket communication works.

[Marco Alka](https://hashnode.com/@maruru)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c04ae2f296bc7fca298281#reply-57c0b4f6387df20e0b9f9425)

there will be one main process which has the connection and distributes the requests to one of your workers. You do not even have to care, just use the socket connections as if there was only one process. You can read more about it in the [official docs](https://nodejs.org/api/cluster.html#cluster_how_it_works)

[Sandeep Acharya](https://hashnode.com/@sandeep1995)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c0403d387df20e0b9f93ad)

Something worth to read.

[shiva prasad](https://hashnode.com/@intelboy)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c00dc3387df20e0b9f936f)

Excellent post . i'm building a node app which is completely stateless and uses JWT for authentication. i'm planning to host the app on 10 servers each having only i cpu CORE (as it is stateless there is no need to bother about session sync) each server has nginx to frontload node app on that particular server . and all these servers will be front loaded by 1 load balancer . so my question is in my scenario do i really require cluster module ?

[Marco Alka](https://hashnode.com/@maruru)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c00dc3387df20e0b9f936f#reply-57c0b636cb80370904fc5929)

You should make a benchmark with one server and see if you get performance improvements by using a cluster with 1,2,3,... processes. As a rule of the thumb, the optimum lies by ca. `<number of CPU cores> + 1` processes

[J Bruni](https://hashnode.com/@jbruni)

[Oct 10, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57c00dc3387df20e0b9f936f#reply-57fadefb2212efbdcbc3f440)

As far as I understood, even having only 1 CPU core, the cluster stills brings to you the benefit of having no downtime when reloading the application on a specific server. Yeah, I know... you already have other 9 servers to take care when 1 server is restarting the app... It may be a "micro-benefit", but it is still a benefit. (Specially if you start with one server alone before adding the others.)

[Aug 25, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57beed2f387df20e0b9f9285)

Hey, nice list there, thanks a lot! I agree with most of your points. But I want to add my little feedback :)

> Not using a reverse proxy

Most reverse proxies are not able to fully leverage the power of HTTP/2 and other modern standards. Sometimes, there is trouble with reverse-proxies and (web-)socket connections. I think there are cases where you really want to expose your Node.JS application to the internet.

> Maintaining global states inside Node web processes

How to maintain state really depends on the kind of application you develop. I work on an application which keeps alive websocket connections with some 500 devices. They have to be manageable over a separate GUI, so I do not have any other choice than to store the connections, if I want to reuse them (and send commands) based on the device-name.

[Marco Alka](https://hashnode.com/@maruru)

[Aug 26, 2016](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57beed2f387df20e0b9f9285#reply-57c0b60e387df20e0b9f9429)

@Reactum yeah, that might be one solution, but why not just write everything you need directly in Node.JS? Even with Go, the service will not perform any better as Node.JS will still be the slowest part in the chain...

[Павел Ефименко](https://hashnode.com/@pavelefimenko)

[Sep 19, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57beed2f387df20e0b9f9285#reply-5ba21f1461e0316151444f17)

author meant that you should store everything in database instead of memory

[Gautham Stalin](https://hashnode.com/@fullstacker)

[Nov 21, 2018](https://hashnode.com/posts/10-things-you-shouldnt-do-while-running-nodejs-in-production/57bee46e93309a25047c619a/comment/57beed2f387df20e0b9f9285#reply-5bf5ba7d3dfb4bea6e470444)

It does makes sense to save javascript objects like sockets in memory. But contents which can be Json Stringified should be saved in memcache (like redis store) and re-used.
