Is there a way for pm2 to run an npm start script or do you just have to run pm2 start app.js
pm2是否有运行npm启动脚本的方法,还是只需要运行pm2启动app.js
So in development
所以在发展
npm start
npm开始
Then in production with pm2 you would run something like
然后在生产pm2时,你会运行类似的东西
pm2 start 'npm start'
pm2 npm开始的开始
There is an equivalent way to do this in forever
有一种等价的方法可以永远这样做
forever start -c "npm start" ./
永远开始-c“npm开始”
7 个解决方案
#1
125
PM2 now supports npm start:
PM2现在支持npm启动:
pm2 start npm -- start
#2
27
Those who are using a configuration script like a .json
file to run the pm2 process can use npm start
or any other script like this -
那些使用配置脚本(如.json文件)来运行pm2进程的用户可以使用npm start或其他类似的脚本
my-app-pm2.json
my-app-pm2.json
{
"apps": [
{
"name": "my-app",
"script": "npm",
"args" : "start"
}
]
}
Then simply -
那么简单,
pm2 start my-app-pm2.json
Edit - To handle the use case when you have this configuration script in a parent directory and want to launch an app in the sub-directory then use the cwd
attribute.
编辑——当您在父目录中拥有此配置脚本并希望在子目录中启动应用程序时,使用cwd属性来处理用例。
Assuming our app is in the sub-directory nested-app
relative to this configuration file then -
假设我们的应用是在子目录nested-app相对于这个配置文件
{
"apps": [
{
"name": "my-nested-app",
"cwd": "./nested-app",
"script": "npm",
"args": "start"
}
]
}
More detail here.
更多细节在这里。
#3
18
I wrote shell script below (named start.sh
). Because my package.json
has prestart
option. So I want to run npm start
.
我在下面编写了shell脚本(名为start.sh)。因为我的包。json已经预先启动选项。我想运行npm start。
#!/bin/bash
cd /path/to/project
npm start
Then, start start.sh
by pm2.
然后,开始的开始。sh pm2。
pm2 start start.sh --name appNameYouLike
#4
11
Yes. Use pm2 start npm --no-automation --name {app name} -- run {script name}
. It works. The --no-automation
flag is there because without it PM2 will not restart your app when it crashes.
是的。使用pm2启动npm——不自动化——名称{app名}——运行{脚本名称}。它的工作原理。无自动化标志是存在的,因为如果没有它,PM2就不会在崩溃时重启你的应用。
#5
7
See to enable clustering:
看到启用集群:
pm2 start npm --name "AppName" -i 0 -- run start
What do you think?
你怎么认为?
#6
1
Unfortunately, it seems that pm2 doesn't support the exact functionality you requested https://github.com/Unitech/PM2/issues/1317.
不幸的是,似乎pm2不支持您所请求的确切功能,https://github.com/unitech/pm2// 1317。
The alternative proposed is to use a ecosystem.json
file Getting started with deployment which could include setups for production and dev environments. However, this is still using npm start
to bootstrap your app.
替代方案是使用生态系统。开始部署的json文件包括用于生产和开发环境的设置。然而,这仍然在使用npm start引导您的应用程序。
#7
0
Now, You can use after:
现在,你可以用after:
pm2 start npm -- start
Follow by https://github.com/Unitech/pm2/issues/1317#issuecomment-220955319
遵循由https://github.com/Unitech/pm2/issues/1317 # issuecomment - 220955319
#1
125
PM2 now supports npm start:
PM2现在支持npm启动:
pm2 start npm -- start
#2
27
Those who are using a configuration script like a .json
file to run the pm2 process can use npm start
or any other script like this -
那些使用配置脚本(如.json文件)来运行pm2进程的用户可以使用npm start或其他类似的脚本
my-app-pm2.json
my-app-pm2.json
{
"apps": [
{
"name": "my-app",
"script": "npm",
"args" : "start"
}
]
}
Then simply -
那么简单,
pm2 start my-app-pm2.json
Edit - To handle the use case when you have this configuration script in a parent directory and want to launch an app in the sub-directory then use the cwd
attribute.
编辑——当您在父目录中拥有此配置脚本并希望在子目录中启动应用程序时,使用cwd属性来处理用例。
Assuming our app is in the sub-directory nested-app
relative to this configuration file then -
假设我们的应用是在子目录nested-app相对于这个配置文件
{
"apps": [
{
"name": "my-nested-app",
"cwd": "./nested-app",
"script": "npm",
"args": "start"
}
]
}
More detail here.
更多细节在这里。
#3
18
I wrote shell script below (named start.sh
). Because my package.json
has prestart
option. So I want to run npm start
.
我在下面编写了shell脚本(名为start.sh)。因为我的包。json已经预先启动选项。我想运行npm start。
#!/bin/bash
cd /path/to/project
npm start
Then, start start.sh
by pm2.
然后,开始的开始。sh pm2。
pm2 start start.sh --name appNameYouLike
#4
11
Yes. Use pm2 start npm --no-automation --name {app name} -- run {script name}
. It works. The --no-automation
flag is there because without it PM2 will not restart your app when it crashes.
是的。使用pm2启动npm——不自动化——名称{app名}——运行{脚本名称}。它的工作原理。无自动化标志是存在的,因为如果没有它,PM2就不会在崩溃时重启你的应用。
#5
7
See to enable clustering:
看到启用集群:
pm2 start npm --name "AppName" -i 0 -- run start
What do you think?
你怎么认为?
#6
1
Unfortunately, it seems that pm2 doesn't support the exact functionality you requested https://github.com/Unitech/PM2/issues/1317.
不幸的是,似乎pm2不支持您所请求的确切功能,https://github.com/unitech/pm2// 1317。
The alternative proposed is to use a ecosystem.json
file Getting started with deployment which could include setups for production and dev environments. However, this is still using npm start
to bootstrap your app.
替代方案是使用生态系统。开始部署的json文件包括用于生产和开发环境的设置。然而,这仍然在使用npm start引导您的应用程序。
#7
0
Now, You can use after:
现在,你可以用after:
pm2 start npm -- start
Follow by https://github.com/Unitech/pm2/issues/1317#issuecomment-220955319
遵循由https://github.com/Unitech/pm2/issues/1317 # issuecomment - 220955319