Intermediate 13 min

Deploy a Node.js app with PM2

Install Node.js, run your API with PM2 and configure the auto restart.

#Node.js#PM2#Deploy

Ready to start your service? Check offers and order online.

View offers and order

Objective

Host an API or a Node.js bot in production with automatic restart thanks to PM2.

PM2
Process manager Node.js

Installation Node.js and PM2

curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt install -y nodejs npm install -g pm2

Deploy application

  1. Cloner or uploader

    Your project in /var/www/monapp, then npm ci --production.

  2. Start with PM2

    pm2 start src/index.js --name monapp

  3. Reverse proxy Nginx

    Proxy to http://127.0.0.1:3000 (see guide Nginx).

  4. Reboot persistence

    pm2 startup then pm2 save

Logs pm2 logs monapp and pm2 monit to monitor CPU/RAM.

Related guides