[英]How to start a package.json script in pm2
I want to demonise my express js graphql api server.我想妖魔化我的 express js graphql api 服务器。 In windows local dev, I can start my server by running this command and it works fine:在windows本地开发中,我可以通过运行这个命令来启动我的服务器,它工作正常:
yarn dev
This start command is defined in my package.json
like this:这个启动命令在我的package.json
定义如下:
"scripts": {
"dev": "cross-env NODE_ENV=development DEBUG=express:* nodemon --exec babel-node src/index.js"
},
When I try to start this in pm2 in my linux server, I get a success like this:当我尝试在我的 linux 服务器的 pm2 中启动它时,我得到了这样的成功:
latheesan@app:~/apps/tweet/server$ pm2 start yarn -- dev
[PM2] Starting /usr/bin/yarn in fork_mode (1 instance)
[PM2] Done.
However, when I type pm2 status
it says error and also the display looks really odd:但是,当我输入pm2 status
它说错误并且显示看起来很奇怪:
I am running this on Ubuntu 16.04
.我在Ubuntu 16.04
上运行它。
If I don't use the pm2
and just start the app in my ubuntu server with yarn dev
- it runs fine.如果我不使用pm2
而只是使用yarn dev
在我的 ubuntu 服务器中启动应用程序 - 它运行良好。
Any ideas?有什么想法吗?
Pm2 now support npm pm2 现在支持 npm
$ pm2 start --interpreter babel-node server.js
(or) (或)
$ pm2 start npm --start
(or) (或)
$ pm2 start npm --name "myAPP" --start
(or) (或)
$ pm2 start npm --name "{app_name}" --run "{script_name}"
I have now resolved this issue.我现在已经解决了这个问题。
Install the babel-node
globally via: npm install -g babel-cli
通过以下方式全局安装babel-node
: npm install -g babel-cli
Then create the pm2 config in json: pm2.json然后在 json 中创建pm2配置: pm2.json
{
"apps": [
{
"name": "Tweet GraphQL Server",
"exec_interpreter": "babel-node",
"script": "index.js",
"merge_logs": true,
"cwd": "./src",
"env": {
"NODE_ENV": "production"
}
}
]
}
Now I can run this command to start the pm2 process: pm2 start pm2.json
现在我可以运行这个命令来pm2 start pm2.json
进程: pm2 start pm2.json
i do this in my app like this:我在我的应用程序中这样做:
in package.json
:在package.json
:
"scripts": {
"start": "... start application script ...",
"start:dev": "... start application script as development mode ...",
"pm2": "pm2 start npm --name \"CustomeNameForPM2\" -- run start --watch",
"pm2:dev": "pm2 start npm --name \"CustomeNameForPM2\" -- run start:dev --watch"
}
now you can run pm2 easy with npm run pm2
or npm run pm2:dev
现在您可以使用npm run pm2
或 npm run pm2:dev
轻松运行pm2:dev
but if you like to do something better, you can read pm2 documentation and use pm2 ecosystem config file但如果你想做得更好,你可以阅读 pm2 文档并使用pm2 生态系统配置文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.