2

What are the best practices for deploying a nodejs application in production?

I would like to know how deploy for production Api's nodejs is being done today, today my application is in docker and running locally.

I wonder if I should use a Nginx inside the container and deploy my server on it or just upload my image node that is already running today.

*I need load balance

Bruno Reis
  • 135
  • 2
  • 7

2 Answers2

3

There are few main types of deployment that are popular today.

  1. Using platform as a service like Heroku
  2. Using a VPS like AWS, Digital Ocean etc.
  3. Using a dedicated server

This list is in the order of growing difficulty and control. So it's easiest with PaaS but you get more control with a dedicated server - thought it gets significantly more difficult, especially when you need to scale out and build clusters.

See this answer for more details on how to install Node on a VPS or a dedicated server:

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177
  • Where is the answer to that link? Is it broken or deleted intentionally? – newguy Aug 15 '17 at 07:29
  • @newguy Thanks for the info. It must have been deleted by mistake but I restored it so you should be able to see it now. By the way, I don't know why someone voted it down, I think all the info is accurate but if you see anything that needs improvement then please comment. Thanks! – rsp Aug 16 '17 at 07:42
2

I can only add from experience on AWS using a NAT Gateway which is a dedicated Node server with a MongoDB server behind the gateway. (Obviously this is a scalable system and project.)

  1. With or without Docker, you need to control the production environment. This means clearly defining which NPM libraries you will need for production, how you handle environment variables and clusters for cores.

  2. I would suggest, very strongly, using a tool like PM2 to handle clusters, server shutdowns and restarts and logs. (Workers & slaves also if you need them and code for them).

This list can go on and on, but keep in mind this is only from an AWS perspective. Setting up a Gateway correctly on AWS is also not an easy process. Be prepared for some gotcha's along the way.

twg
  • 1,075
  • 7
  • 11