In my app, I am using two API's that require different credentials. I am storing each in a .env
file and read them using process.env
. Both .env
and .config
files are in different directories.
The first config.js
:
const dotenv = require('dotenv');
const cfg = {};
dotenv.config({path: '.env'});
cfg.port = process.env.PORT;
cfg.apiKey = process.env.apiKey;
cfg.authDomain = process.env.authDomain;
cfg.databaseURL = process.env.databaseURL;
cfg.projectId = process.env.projectId;
cfg.storageBucket = process.env.storageBucket;
cfg.messagingSenderId = process.env.messagingSenderId;
module.exports = cfg;
The second config.js
const dotenv = require('dotenv');
const cfg = {};
dotenv.config({path: '.env'});
cfg.port = process.env.PORT;
cfg.accountSid = process.env.TWILIO_ACCOUNT_SID;
cfg.authToken = process.env.TWILIO_AUTH_TOKEN;
cfg.twimlAppSid = process.env.TWILIO_TWIML_APP_SID;
cfg.callerId = process.env.TWILIO_CALLER_ID;
module.exports = cfg;
I configured both .env
files the same way. But apparently the second config.js is not able to read the credentials such as: TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, etc. Which led me to believe that for the second .env
file I have to configure differently than the first one.
How do I load the two sets of credentials into one environment? Or do I have to load them into different environments?
Thanks for your time.