Trying to load .env file into to pm2 config - getting error

35 views Asked by At

I have followed every example I can find online and cannot get my pm2 config to correctly load my Node server. I keept getting the error: Error: Cannot find module 'dotenv/config' . I have my .env in a seperate location from my node server. I have created the ecosystem.config.js file by following their docs. Here is the file contents, full directory paths redacted:

module.exports = {
  apps : [{
    name        : "node-server-prod",
    script      : "/my/absolute/path/server.js",
    cwd         : "/my/absolute/path",
    node_args   : "-r dotenv/config",
    args        : "dotenv_config_path=relative/to/cwd/.env"
  }]
}

I tried both absolute and relative paths in the args section. Same with the script path.

I know I have dotenv installed in my node server path. It is not installed in the directory where my ecosystem.config.js file are and where I am calling: pm2 start ecosystem.config.js. I am almost certain it would not need to be installed in that directory. Any help would be much appreciated.

0

There are 0 answers