Wood Chen

How do I run my pnpm prod project with pm2 and keep it in the background?

0 comments543 views137 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

To manage a Node.js application running in production with pm2, follow these steps:

image

  1. Install pm2 globally

    npm install pm2 -g
    
  2. Go to the project root directory and start the application with pm2

    pm2 start npm --name myapp -- run prod
    

    In this command, --name myapp names the application myapp, and run prod runs the npm run prod command.

  3. The application is now running in the background. You can check its status with the following command:

    pm2 status
    
  4. If the application encounters a problem, you can restart it:

    pm2 restart myapp
    
  5. To stop the application, use the following command:

    pm2 stop myapp
    

    To remove the application from pm2 entirely, use the following command:

    pm2 delete myapp
    

These steps let you manage a Node.js application in production with pm2 and keep the process running in the background. When deploying, I recommend using a process manager such as pm2 or forever to keep the application running reliably and handle failures promptly.

Last updated 2024-01-14

Related posts

Comments 0