How do I start my Node.js app with PM2?
Navigate to your project directory, then run pm2 start src/server.js --name devtinder-api. Verify with pm2 status. Run pm2 save to persist the process list so PM2 restarts it on boot.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Installing Node.js and PM2 on AWS EC2 Setting Up the Production Environment
Use the NodeSource repository: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -, then sudo apt install -y nodejs. This installs Node.js 20 LTS and npm.
PM2 is a process manager for Node.js. It keeps your app running, restarts on crash, starts on system boot, and provides log management. Without PM2, the app stops when the SSH session ends or on an unhandled error.
Run pm2 startup systemd, copy and run the outputted command, then run pm2 save to save the current process list. PM2 will automatically restart your apps when the server reboots.
Still have questions?
Browse all our FAQs or reach out to our support team
