New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using PM2 with node-config when NODE_APP_INSTANCE === 0 #2045

Closed
davidhq opened this Issue Mar 27, 2016 · 7 comments

Comments

6 participants
@davidhq

davidhq commented Mar 27, 2016

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:

lorenwest/node-config#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

@aarontropy

This comment has been minimized.

Show comment
Hide comment
@aarontropy

aarontropy Apr 16, 2016

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.

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.

@lahvey

This comment has been minimized.

Show comment
Hide comment

lahvey commented Jun 8, 2016

+1

@sminogue

This comment has been minimized.

Show comment
Hide comment
@sminogue

sminogue Dec 3, 2016

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 :-)

sminogue commented Dec 3, 2016

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 :-)

@vmarchaud

This comment has been minimized.

Show comment
Hide comment
@vmarchaud

vmarchaud Jun 9, 2017

Collaborator

Published under PM2 2.5 : npm install -g pm2@latest && pm2 update

Collaborator

vmarchaud commented Jun 9, 2017

Published under PM2 2.5 : npm install -g pm2@latest && pm2 update

@vmarchaud vmarchaud closed this Jun 9, 2017

@trongvnau

This comment has been minimized.

Show comment
Hide comment
@trongvnau

trongvnau Aug 7, 2017

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

trongvnau commented Aug 7, 2017

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

@vmarchaud

This comment has been minimized.

Show comment
Hide comment
@vmarchaud

vmarchaud Aug 7, 2017

Collaborator

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"
        }
      }
  ]
}
Collaborator

vmarchaud commented Aug 7, 2017

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"
        }
      }
  ]
}
@trongvnau

This comment has been minimized.

Show comment
Hide comment
@trongvnau

trongvnau Aug 7, 2017

@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.

trongvnau commented Aug 7, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment