Last active
December 25, 2024 20:16
-
-
Save Ghepes/a27ad53faba252cc069ab4db72c472a9 to your computer and use it in GitHub Desktop.
Revisions
-
Ghepes revised this gist
Dec 25, 2024 . 2 changed files with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ 1. cd to /Project ### install pm2 ```` npm install pm2 -g This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,8 @@ This mode is intended for development only, not for production. 1. Follow the development command: cd to /Project pm2 start npm --name "my-app-name" -- run dev 2. Add PM2 to ecosystem file @@ -31,7 +33,19 @@ module.exports = { pm2 start ecosystem.config.js 4. When the VM restarts, the app should restart itself. Follow PM2 commands: pm2 save 5. Command Configure PM2 to start automatically on server restart: pm2 startup OTHER commands: Restart and management To view the status of the application: -
Ghepes revised this gist
Dec 25, 2024 . 1 changed file with 52 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ If the application only runs with run dev (development mode) This mode is intended for development only, not for production. 1. Follow the development command: pm2 start npm --name "my-app-name" -- run dev 2. Add PM2 to ecosystem file For advanced management, create an ecosystem.config.js file: ```javascript module.exports = { apps: [ { name: "my-app-name", script: "npm", args: "start", env: { NODE_ENV: "production" } } ] }; ``` 3. Start with: pm2 start ecosystem.config.js OTHER Restart and management To view the status of the application: command: pm2 list To restart the application: command: pm2 restart my-app-name To stop the application: pm2 stop my-app -
Ghepes created this gist
Nov 28, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ ### install pm2 ```` npm install pm2 -g ```` ### add to main project ecosystem.config.js file with next javascript ```` module.exports = { apps: [ { name: 'your-app', script: 'node_modules/next/dist/bin/next', args: 'start -p 3000', exec_mode: 'cluster', instances: 'max', env: { NODE_ENV: 'production', }, }, ], }; ```` ### Build your application for production before starting pm2 ```` npm run build ```` ### Start the application with PM2 ```` pm2 start ecosystem.config.js ```` ### To view the status of the processes, use ```` pm2 status ```` ### Stopping all processes managed by PM2: ```` pm2 stop all ```` ### Delete all processes from the PM2 list: ```` pm2 delete all ```` ### Stopping the PM2 daemon: ```` pm2 kill ```` ### To view the list of processes and associated IDs, use: ```` pm2 list ```` ### Start all applications ```` pm2 start ecosystem.config.js ```` ### Stop all ```` pm2 stop ecosystem.config.js ```` ### Restart all ```` pm2 restart ecosystem.config.js ```` ### Reload all ```` pm2 reload ecosystem.config.js ```` ### Delete all ```` pm2 delete ecosystem.config.js ```` ### To switch between variables in different environment, specify the --env [env name] option: ```` pm2 start process.json --env production pm2 restart process.json --env development ````