Skip to content
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 in startup using dotenv module defined in node_args #2529

Closed
warrenca opened this issue Nov 18, 2016 · 4 comments
Closed

Error in startup using dotenv module defined in node_args #2529

warrenca opened this issue Nov 18, 2016 · 4 comments

Comments

@warrenca
Copy link

TLDR;
I am having an error with the pm2 starting up the application on server start using dotenv module which is defined in node_args of ecosystem.json5.

Long read...
First of all, I am using the dotenv so that i don't need to write all the env config in the ecosystem.json5 instead, I'll look for the .env file. This way, I can git ignore the .env, which contains sensitive info.

I have the following ecosystem content. It works perfectly fine when I just do pm2 start ecosystem.json5. Now I am working on starting the server on OS restart. I followed the tutorials for that just fine (i guess so) but when I looked at the pm2 ls, the server keeps on restarting. then I checked the logs (you can see below), it is looking dotenv module Error: Cannot find module 'dotenv/config'. What could be the cause of the this issue and possible solutions.

{
  apps : [
  {
      name      : "api-server",
      script    : "index.js",
      node_args : "-r dotenv/config"
    }
  ]
}

Software versions used

OS         :  CentOS Linux release 7.2.1511 (Core)
node.js    : v6.9.1
PM2        : 2.1.5

PM2 Log output

Use the command: tail --lines 100 ~/.pm2/pm2.log

    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13552], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:29: App name:parse-server id:0 online
module.js:471
    throw err;
    ^

Error: Cannot find module 'dotenv/config'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at module.js:660:12
    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13566], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: [HandleExit] PM2 is being killed, stopping restart procedure...
2016-11-18 07:21:29: ===============================================================================
2016-11-18 07:21:29: --- Stopping PM2 --------------------------------------------------------------
2016-11-18 07:21:29: Time                 : Fri Nov 18 2016 07:21:29 GMT+0000 (UTC)
2016-11-18 07:21:29: ===============================================================================
2016-11-18 07:21:29: RPC closed
2016-11-18 07:21:29: PUB closed
2016-11-18 07:21:29: PM2 successfully stopped
2016-11-18 07:21:31: ===============================================================================
2016-11-18 07:21:31: --- New PM2 Daemon started ----------------------------------------------------
2016-11-18 07:21:31: Time                 : Fri Nov 18 2016 07:21:31 GMT+0000 (UTC)
2016-11-18 07:21:31: PM2 version          : 2.1.5
2016-11-18 07:21:31: Node.js version      : 6.9.1
2016-11-18 07:21:31: Current arch         : x64
2016-11-18 07:21:31: PM2 home             : /home/centos/.pm2
2016-11-18 07:21:31: PM2 PID file         : /home/centos/.pm2/pm2.pid
2016-11-18 07:21:31: RPC socket file      : /home/centos/.pm2/rpc.sock
2016-11-18 07:21:31: BUS socket file      : /home/centos/.pm2/pub.sock
2016-11-18 07:21:31: Application log path : /home/centos/.pm2/logs
2016-11-18 07:21:31: Process dump file    : /home/centos/.pm2/dump.pm2
2016-11-18 07:21:31: Concurrent actions   : 2
2016-11-18 07:21:31: SIGTERM timeout      : 1600
2016-11-18 07:21:31: ===============================================================================
2016-11-18 07:21:37: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:37: App name:parse-server id:0 online
[centos@ip-10-0-4-231 IMS_Parse_Server]$ node --version
v6.9.1
[centos@ip-10-0-4-231 IMS_Parse_Server]$ lsb_release -d
-bash: lsb_release: command not found
[centos@ip-10-0-4-231 IMS_Parse_Server]$ lsb_release -d
-bash: lsb_release: command not found
[centos@ip-10-0-4-231 IMS_Parse_Server]$  cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
[centos@ip-10-0-4-231 IMS_Parse_Server]$ pm2 --version
2.1.5
[centos@ip-10-0-4-231 IMS_Parse_Server]$ tail --lines 100 ~/.pm2/pm2.log
    at bootstrap_node.js:509:3
2016-11-18 07:21:28: App name:parse-server id:0 disconnected
2016-11-18 07:21:28: App [parse-server] with id [0] and pid [13512], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:28: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:29: App name:parse-server id:0 online
module.js:471
    throw err;
    ^

Error: Cannot find module 'dotenv/config'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at module.js:660:12
    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13532], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:29: App name:parse-server id:0 online
module.js:471
    throw err;
    ^

Error: Cannot find module 'dotenv/config'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at module.js:660:12
    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13544], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:29: App name:parse-server id:0 online
module.js:471
    throw err;
    ^

Error: Cannot find module 'dotenv/config'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at module.js:660:12
    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13552], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:29: App name:parse-server id:0 online
module.js:471
    throw err;
    ^

Error: Cannot find module 'dotenv/config'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at module.js:660:12
    at Array.forEach (native)
    at Function.Module._preloadModules (module.js:659:12)
    at preloadModules (bootstrap_node.js:365:38)
    at startup (bootstrap_node.js:148:9)
    at bootstrap_node.js:509:3
2016-11-18 07:21:29: App name:parse-server id:0 disconnected
2016-11-18 07:21:29: App [parse-server] with id [0] and pid [13566], exited with code [1] via signal [SIGINT]
2016-11-18 07:21:29: [HandleExit] PM2 is being killed, stopping restart procedure...
2016-11-18 07:21:29: ===============================================================================
2016-11-18 07:21:29: --- Stopping PM2 --------------------------------------------------------------
2016-11-18 07:21:29: Time                 : Fri Nov 18 2016 07:21:29 GMT+0000 (UTC)
2016-11-18 07:21:29: ===============================================================================
2016-11-18 07:21:29: RPC closed
2016-11-18 07:21:29: PUB closed
2016-11-18 07:21:29: PM2 successfully stopped
2016-11-18 07:21:31: ===============================================================================
2016-11-18 07:21:31: --- New PM2 Daemon started ----------------------------------------------------
2016-11-18 07:21:31: Time                 : Fri Nov 18 2016 07:21:31 GMT+0000 (UTC)
2016-11-18 07:21:31: PM2 version          : 2.1.5
2016-11-18 07:21:31: Node.js version      : 6.9.1
2016-11-18 07:21:31: Current arch         : x64
2016-11-18 07:21:31: PM2 home             : /home/centos/.pm2
2016-11-18 07:21:31: PM2 PID file         : /home/centos/.pm2/pm2.pid
2016-11-18 07:21:31: RPC socket file      : /home/centos/.pm2/rpc.sock
2016-11-18 07:21:31: BUS socket file      : /home/centos/.pm2/pub.sock
2016-11-18 07:21:31: Application log path : /home/centos/.pm2/logs
2016-11-18 07:21:31: Process dump file    : /home/centos/.pm2/dump.pm2
2016-11-18 07:21:31: Concurrent actions   : 2
2016-11-18 07:21:31: SIGTERM timeout      : 1600
2016-11-18 07:21:31: ===============================================================================
2016-11-18 07:21:37: Starting execution sequence in -cluster mode- for app name:parse-server id:0
2016-11-18 07:21:37: App name:parse-server id:0 online
@vmarchaud
Copy link
Contributor

Configure cwd entry in your process file, the file you want to include isn't where it supposed to be.

@ghashi
Copy link

ghashi commented Sep 18, 2018

@warrenca , how did you solve this issue?

In this specific case (using dotenv) I required dotenv on my code instead of using preload (via node -r option) setup, i.e., I used this setup instead of this one

@yalamber
Copy link

I am having same issue? How do we configure cwd entry?

@sgywzy
Copy link

sgywzy commented Jun 1, 2020

Configure cwd entry in your process file, the file you want to include isn't where it supposed to be.

I am having same issue? How do we configure cwd entry?

module.exports = {
  apps: [{
    name: 'app1 name',
    script: 'app1.js',
    cwd: '/path/to/folder/',
    exec_mode: 'fork_mode',
    node_args: '-r dotenv/config',
  }, {
    name: 'app2 name',
    script: 'app1.js',
    cwd: '/path/to/folder/',
    instances: 'max',
    exec_mode: 'cluster',
    node_args: '-r dotenv/config',
  }, {
    name: 'app2 name',
    script: 'app1.js',
    cwd: '/path/to/folder/',
    exec_mode: 'fork_mode',
    node_args: '-r dotenv/config',
  }],
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants