I have two dotenv files, one for development and another for test.
const dotenv = require('dotenv');
if (process.env && process.env.NODE_ENV) {
dotenv.config({path: '.env.' + process.env.NODE_ENV});
} else {
dotenv.config({path: '.env.development'});
}
const http = require('http');
const app = require('../src/app');
const port = parseInt(process.env.PORT, 10) || 8000;
app.set('port', port);
const server = http.createServer(app);
server.listen(port);
Here are my questions:
When does server load dotenv files in my case? If I run in test
env, why do I get undefined for those process.env variables?
It seems to me this file only runs once, when I change NODE_ENV, it does not change which file to load.
So in short:
My development dotenv is working, but just having trouble when changing it to test
dotenv