I had big problems using PM2 today with nginx (reverse proxy):
http://serverfault.com/questions/766280/nginx-proxy-pass-cannot-fetch-assets
This seems to be the issue:
https://github.com/lorenwest/node-config/issues/244
and not just warning, I cannot run this app with pm2 at all... is there a way to make this seamlessly work? Does pm2 need a bugfix or it's just not compatible with config package? I tried creating the default-0.json with {} as described in that thread but it didn't help...
This was a hard one to discover that pm2 is at fault... forever and passenger work in this same case...
thank you
I'm having the exact same problem and the default-0.json hack didn't work for me either.
The problem is that both PM2 and node-config use the same environment variable, but for very different purposes, and neither provide a namespace.
In the original thread (#1143) that requested the NODE_APP_INSTANCE feature, it was suggested that the name of the environment variable should be configurable. Can we implement that feature? If the environment variable defaults to NODE_APP_INSTANCE it would be a non-breaking change.
+1
Same issue here... #244 is marked as fixed which I think is crap since it smells like a total hack. This bug is sitting open for like 9 months with no motion... Think I am going to write off PM2 and move on. I'll take a look at forever and passenger thanks :-)
Published under PM2 2.5 : npm install -g pm2@latest && pm2 update
Here is what i did to address the issue after reading all of the solutions proposed
1- On your server, make sure you have a "config" folder in your project (/var/www/your website name/config)
2- In config folder, make sure you have the configuration files: default.js, development.js, production.js (or json if you prefer)
3- If you use pm2 version less than 2.5, in config folder, create default-0.js with {} as a content (or default-0.json). For pm2 v2.5+ skip step 3 (@vmarchaud thanks for the advice below)
4- Create pm2.config.js like below in your server (put in root folder for example)
NOTE: Setting instance_var: 'INSTANCE_ID' and NODE_CONFIG_DIR are super important
refer to
https://github.com/lorenwest/node-config/wiki/Configuration-Files
http://pm2.keymetrics.io/docs/usage/environment/#specific-environment-variables
docs
module.exports = {
apps : [
{
name : 'process-name',
script : './app.js',
cwd : '/var/www/<your website name>/',
instance_var: 'INSTANCE_ID',
env: {
"PORT": 3000,
"NODE_ENV": 'development',
"NODE_CONFIG_DIR": "/var/www/<your website name>/config/"
},
env_production : {
"PORT": 8080,
"NODE_ENV": 'production',
"NODE_CONFIG_DIR": "/var/www/<your website name>/config/"
}
}
]
};
5- $ pm2 start pm2.config.js --env production
You have a way to avoid this problem with pm2 2.5 (see docs) :
You may have problems with node-config with the NODE_APP_INSTANCE name,
so you can rename it with instance_var options :
module.exports = {
apps : [
{
name: "myapp",
script: "./app.js",
watch: true,
instance_var: 'INSTANCE_ID',
env: {
"PORT": 3000,
"NODE_ENV": "development"
}
}
]
}
@vmarchaud I am using v2.6.1 and i can confirm that i don't need an empty default-0.js/json file.
instance_var and NODE_CONFIG_DIR settings are important to set correctly. I have updated my previous comment, thanks.
Most helpful comment
I'm having the exact same problem and the
default-0.jsonhack didn't work for me either.The problem is that both PM2 and node-config use the same environment variable, but for very different purposes, and neither provide a namespace.
In the original thread (#1143) that requested the
NODE_APP_INSTANCEfeature, it was suggested that the name of the environment variable should be configurable. Can we implement that feature? If the environment variable defaults toNODE_APP_INSTANCEit would be a non-breaking change.