You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
For some reason, when i want run a app created with CompoundJS with pm2, the aplication doesn't start (but in other ways, like node server.js, using nodemon or forever, the problem doesn't happen).
The script server.js is generic (automatically created by Compound):
#!/usr/bin/env node
/** * Server module exports method returning new instance of app. * * @param {Object} params - compound/express webserver initialization params. * @returns CompoundJS powered express webserver */varapp=module.exports=functiongetServerInstance(params){params=params||{};// specify current dir as default root of serverparams.root=params.root||__dirname;returnrequire('compound').createServer(params);};if(!module.parent){varport=process.env.PORT||3000;varhost=process.env.HOST||'0.0.0.0';varserver=app();server.listen(port,host,function(){console.log('Compound server listening on %s:%d within %s environment',host,port,server.set('env'));});}
And the console don't show any problem:
$ pm2 start server.js -v
⌬ PM2 Configuration : { script: 'server.js', name: 'server' }
⌬ PM2 You can write the current configuration by adding -w option
{ script: 'server.js',
name: 'server',
pm_exec_path: '<path>/server.js' }
⌬ PM2 Process launched
Any idea? Specifically i don't know if this a problem with compoundjs or with pm2.
Best regards
The text was updated successfully, but these errors were encountered:
Yes it doesn't work because in the server.js CompoundJS use module.parent, and as pm2 wrap the code in child process the code is not executed.
To fix it :
#!/usr/bin/env node
/** * Server module exports method returning new instance of app. * * @param {Object} params - compound/express webserver initialization params. * @returns CompoundJS powered express webserver */varapp=module.exports=functiongetServerInstance(params){params=params||{};// specify current dir as default root of serverparams.root=params.root||__dirname;returnrequire('compound').createServer(params);};//if (!module.parent) {varport=process.env.PORT||3000;varhost=process.env.HOST||'0.0.0.0';varserver=app();server.listen(port,host,function(){console.log('Compound server listening on %s:%d within %s environment',host,port,server.set('env'));});//}
Hi,
For some reason, when i want run a app created with CompoundJS with pm2, the aplication doesn't start (but in other ways, like
node server.js
, usingnodemon
orforever
, the problem doesn't happen).The script server.js is generic (automatically created by Compound):
And the console don't show any problem:
Any idea? Specifically i don't know if this a problem with compoundjs or with pm2.
Best regards
The text was updated successfully, but these errors were encountered: