Deploy node.js in production

2020-04-16 04:35发布

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

2条回答
The star\"
2楼-- · 2020-04-16 04:51

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:

查看更多
仙女界的扛把子
3楼-- · 2020-04-16 05:03

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.

查看更多
登录 后发表回答