Running NodeJS server in production Running NodeJS server in production nginx nginx

Running NodeJS server in production


You may consider forever or supervisor.

Check this blog post on the same.


You can also use docker. You can create multiple docker containers that will run your node server. Now at the nginx level at your host machine you can do load balancing configuration which will route the traffic equally to different docker node containers this will improve your availability and scalability, In heavy traffic you just need to increase the number of docker node containers as and when required. I guess initially 2 containers will be enough to handle traffic (depends on your use case though).

Note:- You can also use forever or supervisor as suggested by @Rajesh Gupta inside your docker containers for running node server. We use PM2 for that.

If you have a database then you can create a separate docker container for the database and map it to a volume in your host machine.

You can learn about docker from here.

Also you can read about load balancing in nginx from here.

Further more to improve your availability you can add a caching layer in between nginx and docker containers. Varnish is the best caching service i have used till date.

PS:- We use a similar but more advanced architecture to run our Ecommerce application that generates 5-10k orders daily. So this is a tested approach with 0 downtime.


Try to dockerize the whole app including the db, caching server (if any) etc. Here are some examples why:

  • You can launch a fully capable development environment on anycomputer supporting Docker; you don't have to install libraries,dependencies, download packages, mess with config files etc.

  • The working environment of the application remains consistent acrossthe whole workflow. This means the app runs exactly the same for
    developer, tester, and client, be it on development, staging or
    production server. In short, Docker is the counter-measure for the
    age-old response in the software development: "Strange, it works for me!"

Every application requires a specific working environment: pre-installed applications, dependencies, data bases, everything in specific version. Docker containers allow you to create such environments. Contrary to VM, however, the container doesn't hold the whole operating system—just applications, dependencies, and configuration. This makes Docker containers much lighter and faster than regular VM's.