dotenv
will read .env
file located in the current directory.
When you call pm2 start myapp/app.js
it won’t search for myapp/.env
.
.env // It will try to load this, which doesn't exist
myapp/
app.js
So you have two solutions
use path
option:
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '.env') });
Or call your script from inside myapp/
pm2 start app.js