您使用 express v4.x 构建 node.js 应用程序,然后通过 npm start 启动您的应用程序。我的问题是如何停止应用程序?有npm stop吗?
EDIT 以在实现 npm stop
时包含错误/home/nodetest2# npm stop
> nodetest2@0.0.1 stop /home/nodetest2
> pkill -s SIGINT nodetest2
pkill: invalid argument for option 's' -- SIGINT
npm ERR! nodetest2@0.0.1 stop: `pkill -s SIGINT nodetest2`
npm ERR! Exit status 2
最佳答案
是的,npm 也提供了一个停止脚本:
npm 帮助 npm 脚本
prestop, stop, poststop: Run by the npm stop command.
在你的 package.json 中设置上述之一,然后使用 npm stop
npm help npm-stop
如果你在 app.js
中设置,你可以让这个变得非常简单,
process.title = myApp;
然后,在scripts.json中,
"scripts": {
"start": "app.js"
, "stop": "pkill --signal SIGINT myApp"
}
也就是说,如果是我,我会使用 pm2
或基于 git push 自动处理的东西。
关于node.js - 如何停止 node.js 表达 'npm start' 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23258421/