Last active
October 31, 2024 18:28
-
-
Save Korveld/c539ec916a1c1ecd149293e09358ced7 to your computer and use it in GitHub Desktop.
PM2 cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install pm2@latest -g | |
pm2 start "node --env-file=.env dist/server.js" --name ws-satchel | |
pm2 list | |
pm2 stop ws-satchel | |
pm2 restart ws-satchel | |
pm2 logs ws-satchel | |
pm2 delete ws-satchel | |
Auto-start on Server Reboot: To ensure your Node.js app starts automatically when the server reboots, run this command: | |
pm2 startup | |
pm2 save | |
pm2 unstartup systemd | |
Config file example | |
module.exports = { | |
apps: [{ | |
name: 'ws-satchel', | |
script: 'dist/server.js', | |
env: { | |
SSL_CERT_PATH: 'cert.pem', | |
SSL_PRIVATE_KEY_PATH: 'privkey.pem', | |
SSL_CHAIN_PATH: 'chain.pem' | |
} | |
}] | |
}; | |
OR | |
module.exports = { | |
apps: [{ | |
name: 'ws-satchel', | |
script: 'dist/server.js', | |
env_file: '.env' | |
}] | |
}; | |
pm2 start ecosystem.config.cjs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment