在 Windows 中通过 pm2 执行 npm 脚本的问题 [英] Issue with executing npm scripts via pm2 in Windows

查看:70
本文介绍了在 Windows 中通过 pm2 执行 npm 脚本的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ecosystem.json as,通过 pm2 运行 npm 自定义脚本,

I am trying to run npm custom scripts via pm2 using ecosystem.json as,

{
    "apps": [{
        "name": "Service",
        "script": "npm",
        "args": "run command"
    }]
}

很遗憾我做不到.谁能帮我解决这个问题?我得到如下所示,

Unfortunately I am unable to do it. Can anyone help me to get through this? I am getting as shown below,

C:\PROGRAM FILES\NODEJS\NPM.CMD:1
0|Service | (function (exports, require, module, __filename, __dirname) { :: 
Created by npm, please don't edit manually.
0|Service |                                                               ^
0|Service | SyntaxError: Unexpected token :
0|Service |     at createScript (vm.js:56:10)
0|Service |     at Object.runInThisContext (vm.js:97:10)
0|Service |     at Module._compile (module.js:542:28)
0|Service |     at Object.Module._extensions..js (module.js:579:10)
0|Service |     at Module.load (module.js:487:32)
0|Service |     at tryModuleLoad (module.js:446:12)
0|Service |     at Function.Module._load (module.js:438:3)
0|Service |     at Object.<anonymous> 
(C:\Users\AD001\AppData\Roaming\npm\node_modules\pm2\
lib\ProcessContainerFork.js:53:21)
0|Service |     at Module._compile (module.js:570:32)
0|Service |     at Object.Module._extensions..js (module.js:579:10)

推荐答案

这是 pm2 中报告的问题.你可以通过做来解决

this is a reported issue in pm2. you can work around by doing

//startscript.js
var exec = require('child_process').exec;
exec('npm start', {windowsHide: true});

然后pm2 启动 startscript.js

then pm2 start startscript.js

这篇关于在 Windows 中通过 pm2 执行 npm 脚本的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆