nodejs常驻后台运行

nodejs是经过命令行方式执行,当用户断开时Nodejs也就中止运行了。下面介绍几种办法让Nodejs常驻在后台运行node

pm2(推荐)

官网地址:pm2.io/git

npm install -g pm2
pm2 start app.js        // 启动
pm2 start app.js -i max //启动 使用全部CPU核心的集群
pm2 stop app.js         // 中止
pm2 stop all            // 中止全部
pm2 restart app.js      // 重启
pm2 restart all         // 重启全部
pm2 delete  app.js      // 关闭
复制代码

nohup

nohup node app.js &
复制代码

forever

github地址: github.com/nodejitsu/f…github

npm install forever -g
forever start app.js    //启动
forever stop app.js     //关闭
forever stopall         //关闭所有
forever restart app.js  //重启
forever restartall      //重启所有
复制代码
相关文章
相关标签/搜索