简体   繁体   English

PM2启动npm-启动错误

[英]PM2 start npm — start error

I have been using "npm start" to start up my express server (for my angular 2 cli project) for a couple of weeks and it works fine except it doesn't restart automatically when crashed. 我已经使用“ npm start”启动我的Express服务器(对于我的angular 2 cli项目)已经有几个星期了,它工作正常,但崩溃时不会自动重新启动。 Now, to make it restart automatically, I tried to use PM2. 现在,为了使其自动重启,我尝试使用PM2。 Based on my research, it should be as simple as running 根据我的研究,它应该像运行一样简单

pm2 start npm -- start

However, this gives me "stopped" status right away. 但是,这立即使我处于“已停止”状态。 Doing "pm2 show" leads me to look at the error in npm-error-0.log, and there I see this error 进行“ pm2 show”会使我查看npm-error-0.log中的错误,在那里我看到了此错误

SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Object.<anonymous> (C:\Users\mingliu_99\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:83:21)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^

This is my start script in my package.json file: 这是我的package.json文件中的启动脚本:

"start": "cross-env NODE_ENV=production node dist-prod/server.js"

So, what's the problem here? 那么,这是什么问题呢?

By the way, when I try with this command 顺便说一句,当我尝试使用此命令时

pm2 start dist-prod/server.js

it seems to be started fine (with green online status). 看来一切正常(在线状态为绿色)。 However, the server is not serving, which is probably because the env parameter is missing. 但是,服务器未在服务,这可能是因为缺少env参数。

UPDATE: 更新:

I found this and it turns out to be a problem of pm2 on windows 10. 我发现了这一点 ,事实证明这是Windows 10上pm2的问题。

The workaround suggested in the end of that post seems to work fine. 该帖子结尾处建议的解决方法似乎工作正常。

Basically, install node-cmd first, and create a startscript.js: 基本上,首先安装node-cmd,然后创建一个startscript.js:

var cmd=require('node-cmd'); 
cmd.run('npm start');

and then run 然后运行

pm2 start startscript.js

You have to reference the server setup scripts Eg. 您必须参考服务器设置脚本,例如。 pm2 start app:name backend scripts

In this case your scripts is any script.js listening to your server. 在这种情况下,您的脚本就是侦听服务器的任何script.js。

To watch and reload instantly use pm2 start app:name backend scripts --watch 要立即观看和重新加载,请使用pm2 start app:name backend脚本--watch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM