I want to set up PM2 as follows:
For development env:
watch: ['app', 'config', '.env'],
For production env
watch: false
How to implement this approach?
I tried to create two separate files with different settings for the environment. But now I'm getting an error when trying to run
pm2 startOrRestart ./config/pm2-development.js --only madpost
[PM2] Spawning PM2 daemon with pm2_home=/home/alex/.pm2
[PM2] PM2 Successfully daemonized
/usr/lib/node_modules/pm2/lib/API.js:866
if (config.deploy)
^
TypeError: Cannot read property 'deploy' of undefined
at module.exports.API._startJson (/usr/lib/node_modules/pm2/lib/API.js:866:13)
at Command.<anonymous> (/usr/lib/node_modules/pm2/bin/pm2:296:9)
at Command.listener (/usr/lib/node_modules/pm2/node_modules/commander/index.js:301:8)
at emitTwo (events.js:125:13)
at Command.emit (events.js:213:7)
at Command.parseArgs (/usr/lib/node_modules/pm2/node_modules/commander/index.js:615:12)
at Command.parse (/usr/lib/node_modules/pm2/node_modules/commander/index.js:458:21)
at beginCommandProcessing (/usr/lib/node_modules/pm2/bin/pm2:120:13)
at /usr/lib/node_modules/pm2/bin/pm2:194:7
at /usr/lib/node_modules/pm2/lib/API.js:158:14
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `pm2 startOrRestart ./config/pm2-development.js --only madpost`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/alex/.npm/_logs/2017-06-07T14_23_11_830Z-debug.log
Could you share your configuration ?
./config/pm2.prod.js
module.exports = {
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps: [{
name: 'madpost',
script: 'server.js',
exec_mode : "cluster",
instances : 0,
watch: false,
},{
name: 'madpost-cron',
script: 'cron.js',
}],
}
./config/pm2.dev.js
module.exports = {
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps: [{
name: 'madpost',
script: 'server.js',
watch: ['app', 'bootstrap', 'config', '.env']
},{
name: 'madpost-cron',
script: 'cron.js',
}],
}
$ pm2 startOrRestart ./config/pm2.dev.js
/usr/lib/node_modules/pm2/lib/API.js:866
if (config.deploy)
^
TypeError: Cannot read property 'deploy' of undefined
at module.exports.API._startJson (/usr/lib/node_modules/pm2/lib/API.js:866:13)
at Command.<anonymous> (/usr/lib/node_modules/pm2/bin/pm2:296:9)
at Command.listener (/usr/lib/node_modules/pm2/node_modules/commander/index.js:301:8)
at emitTwo (events.js:125:13)
at Command.emit (events.js:213:7)
at Command.parseArgs (/usr/lib/node_modules/pm2/node_modules/commander/index.js:615:12)
at Command.parse (/usr/lib/node_modules/pm2/node_modules/commander/index.js:458:21)
at beginCommandProcessing (/usr/lib/node_modules/pm2/bin/pm2:120:13)
at /usr/lib/node_modules/pm2/bin/pm2:194:7
at /usr/lib/node_modules/pm2/lib/API.js:153:14
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `pm2 startOrRestart ./config/pm2.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/alex/.npm/_logs/2017-06-12T16_47_50_858
md5-9edd24176c14bfde59d35c910dec819b
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]~predev: [email protected]
6 silly lifecycle [email protected]~predev: no script for predev, continuing
7 info lifecycle [email protected]~dev: [email protected]
8 verbose lifecycle [email protected]~dev: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~dev: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/run/media/alex/LinWin/Develop/fb-scaner/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
10 verbose lifecycle [email protected]~dev: CWD: /run/media/alex/LinWin/Develop/fb-scaner
11 silly lifecycle [email protected]~dev: Args: [ '-c', 'pm2 startOrRestart ./config/pm2.dev.js' ]
12 silly lifecycle [email protected]~dev: Returned: code: 1 signal: null
13 info lifecycle [email protected]~dev: Failed to exec dev script
14 verbose stack Error: [email protected] dev: `pm2 startOrRestart ./config/pm2.dev.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:283:16)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at EventEmitter.emit (events.js:213:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at ChildProcess.emit (events.js:213:7)
14 verbose stack at maybeClose (internal/child_process.js:887:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid [email protected]
16 verbose cwd /run/media/alex/LinWin/Develop/fb-scaner
17 verbose Linux 4.11.3-1-ARCH
18 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
19 verbose node v8.1.0
20 verbose npm v5.0.3
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] dev: `pm2 startOrRestart ./config/pm2.dev.js`
23 error Exit status 1
24 error Failed at the [email protected] dev script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
I'd also like to know if this is a valid approach. Currently it doesn't work like that or I may have misconfigured something.
using startOrRestart command gives me that error as well. (Cannot read property 'deploy' of undefined). Using start/restart separately makes it work as normal
I'm also having this issue. Is there any way to make startOrRestart work without having to resort to start/restart ?
Edit: Nevermind, adding a configuration file fixed the issue. I was running a command directly without config.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
using
startOrRestartcommand gives me that error as well. (Cannot read property 'deploy' of undefined). Usingstart/restartseparately makes it work as normal