xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

PM2 & chmod +x All In One

PM2 & chmod +x All In One

https://www.npmjs.com/package/pm2

https://github.com/Unitech/pm2

docs

https://pm2.io/doc/en/runtime/quick-start/

old

https//pm2.keymetrics.io/docs/usage/quick-start/

https://pm2.io/doc/en/runtime/overview/

https://pm2.io/doc/en/runtime/guide/installation/

PM2 ecosystem.config.js

ecosystem.config.js

module.exports = {
  apps : [{
    name: "app",
    script: "./app.js",
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }]
}

# $ pm2 [start|restart|stop|delete] ecosystem.config.js

$ pm2 start ecosystem.config.js

https://doc.pm2.io/en/runtime/guide/ecosystem-file/

https://pm2.keymetrics.io/docs/usage/application-declaration/

https://stackoverflow.com/questions/47166609/how-can-i-get-pm2-to-use-my-ecosystem-config-js-file-on-reboot

# install
$ npm install pm2 -g

image

image

$ pm2 list

$ mp2 start server.js

image

linux & chmod 755

https://github.com/xgqfrms-GitHub/Node-CLI-Tools/blob/master/bash-shell-chmod.md


#!/bin/sh

# echo "^-v-^ JSON DB is running in development env!" && npm run db

# echo "^-v-^ JSON DB is running in development env!" && nodemon -w ./server.js localhost 8888

JSONDB="nodemon -w ./server.js localhost 8888"

${JSONDB} &
# chmod +x db.sh
# sudo ./db.sh
# nodemon -w ./server.js localhost 8888

# /bin/sh db.sh

# ps -ef | grep node
# sudo kill -9 <PID>

not a shell bug

ok

image

daemon

后台守护进程

nodemon

https://nodemon.io/

https://github.com/remy/nodemon#nodemon

https://www.npmjs.com/package/nodemon

$ npm install -g nodemon

$ npm i -D nodemon

$ yarn global add  nodemon

$ yarn add -D nodemon

$ nodemon ./server.js localhost 8080

$ nodemon --inspect ./server.js 80


$ ./node_modules/nodemon/bin/nodemon ./server.js localhost 8080

$ ./node_modules/nodemon/bin/nodemon --inspect ./server.js 80

pm2

https://www.npmjs.com/package/pm2

https://github.com/Unitech/pm2

docs

https://pm2.io/doc/en/runtime/quick-start/

$ yarn global add pm2

# $ pm2 [start|restart|stop|delete] ecosystem.config.js

$ pm2 start ecosystem.config.js
$ pm2 restart ecosystem.config.js
$ pm2 stop ecosystem.config.js
# $ pm2 delete ecosystem.config.js

$ yarn add -D pm2

$ ./node_modules/pm2/bin/pm2 start ecosystem.config.js
$ ./node_modules/pm2/bin/pm2 restart ecosystem.config.js
$ ./node_modules/pm2/bin/pm2 stop ecosystem.config.js
# $ ./node_modules/pm2/bin/pm2 delete ecosystem.config.js

// ecosystem.config.js
module.exports = {
  apps : [{
    name: "app",
    script: "./app.js",
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }]
}

demos

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2018-09-11 11:37  xgqfrms  阅读(228)  评论(17编辑  收藏  举报