31 lines
658 B
JavaScript
31 lines
658 B
JavaScript
|
const pm2 = require('pm2');
|
||
|
|
||
|
function startPm2Process(process_name, file, path, port) {
|
||
|
|
||
|
pm2.connect(function (err) {
|
||
|
if (err) {
|
||
|
console.error(err);
|
||
|
// process.exit(2);
|
||
|
}
|
||
|
|
||
|
pm2.start({
|
||
|
name: process_name,
|
||
|
script: file,
|
||
|
cwd: path,
|
||
|
env: {
|
||
|
PORT: port
|
||
|
}
|
||
|
// additional options here if needed
|
||
|
}, function (err, apps) {
|
||
|
if (err) {
|
||
|
console.error(err);
|
||
|
// process.exit(2);
|
||
|
}
|
||
|
|
||
|
pm2.disconnect();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
module.exports = startPm2Process
|