nodejs forever:如何运行我的npm应用程序

man*_*ish 12 node.js forever

现在我运行我的nodejs应用程序为npm start.我想在后台运行它.我找到forever了这个包,但不知道我怎么能运行我通常运行的应用程序npm start.那我怎么能用它来运行呢forever

我遵循这个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
Run Code Online (Sandbox Code Playgroud)

除此之外还有其他更好的方法在后台运行nodejs吗?

ala*_*rev 24

你做得对.

警告只是提醒您缺少一些基本信息,因此它会分配默认值.确切地说,如果你的脚本在启动后很快就会崩溃/退出,那么永远也会退出.


如果您想摆脱这些警告:

forever start --minUptime 1000 --spinSleepTime 1000 app.js 
Run Code Online (Sandbox Code Playgroud)

此外,您可以打开package.json文件,找到:

  "scripts": {
    "start": "node app.js"
  },
Run Code Online (Sandbox Code Playgroud)

并将其更改为:

  "scripts": {
    "start": "forever start --minUptime 1000 --spinSleepTime 1000 app.js",
    "stop":  "forever stop app.js"
  },
Run Code Online (Sandbox Code Playgroud)

现在你可以使用npm start它,它会forever自动调用.

  • 对于任何看到这个谁使用快速生成器并使用"npm start"启动应用程序的人,将"app.js"替换为"\`pwd \`/ bin/www" (3认同)

Nis*_*hah 8

2020年

使用forevernpm 包 ( https://www.npmjs.com/package/forever )

永远开始 -c "npm <command>" /path/to/app/dir/

例子

./ 表示当前目录

永远开始 -c "npm start" ./