现在我将我的 nodejs 应用程序作为 npm start
运行。我想在后台运行它。我为此找到了 forever
包,但不知道如何运行我通常以 npm start
运行的应用程序。那么如何使用 forever
运行它?
我关注 this SO但收到此错误:
ENVIRONMENT=production forever start app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
除此之外,还有其他更好的方式在后台运行 nodejs 吗?
最佳答案
你做得对。
警告只是提醒您缺少一些基本信息,因此它分配了默认值。确切地说,如果您的脚本在启动后不到一秒就崩溃/退出,forever 也会退出。
如果您想摆脱这些警告:
forever start --minUptime 1000 --spinSleepTime 1000 app.js
另外,你可以打开package.json
文件,找到:
"scripts": {
"start": "node app.js"
},
并将其更改为:
"scripts": {
"start": "forever start --minUptime 1000 --spinSleepTime 1000 app.js",
"stop": "forever stop app.js"
},
现在你可以使用npm start
,它会自动调用forever
。
关于node.js - nodejs永远: How to run my npm application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27273993/