是否有一种方法让pm2运行npm启动脚本,或者你只需要运行pm2 start app.js
所以在发展中
npm start
然后在使用pm2的生产中,你会运行这样的程序
pm2 start 'npm start'
有一种等效的方法可以永远做到这一点:
forever start -c "npm start" ./
是否有一种方法让pm2运行npm启动脚本,或者你只需要运行pm2 start app.js
所以在发展中
npm start
然后在使用pm2的生产中,你会运行这样的程序
pm2 start 'npm start'
有一种等效的方法可以永远做到这一点:
forever start -c "npm start" ./
当前回答
使用npm运行
Pm2启动NPM——name "{app_name}"——run {script_name}
其他回答
我需要在我的应用程序pm2中运行一个特定的npm脚本(对于每个env) 在我的例子中,是当我创建一个登台/测试服务时
对我有用的命令(参数必须这样转发):
pm2 start npm --name "my-app-name" -- run "npm:script"
例子:
pm2 start npm --name "myApp" -- run "start:test"
pm2 start npm --name "myApp" -- run "start:staging"
pm2 start npm --name "myApp" -- run "start:production"
希望有帮助
是的。使用pm2启动npm——no-automation——name{应用程序名称}——运行{脚本名称}。它的工作原理。——no-automation标志的存在是因为如果没有它,PM2将不会在应用崩溃时重新启动应用。
我在下面写了shell脚本(名为start.sh)。 因为我的包裹。Json有预启动选项。 我想运行npm start。
#!/bin/bash
cd /path/to/project
npm start
然后,通过pm2启动start.sh。
pm2 start start.sh --name appNameYouLike
现在,你可以用after:
pm2 start npm -- start
关注https://github.com/Unitech/pm2/issues/1317#issuecomment-220955319
首先,您需要创建一个run.js文件,并将下面的代码粘贴到该文件上。
const { spawn } = require('child_process');
//here npm.cmd for windows.for others only use npm
const workerProcess = spawn('npm.cmd', ['start']);
workerProcess.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
workerProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
workerProcess.on('close', function (code) {
console.log('child process exited with code ' + code);
});
然后用pm2运行这个文件。
pm2 start run.js
列表项