For node.js you can create your own env
files that contain different values that better suites your environemnt
.env.test
API_KEY=TEST_API_KEY
.env.dev
API_KEY=DEV_API_KEY
to run node with this env variables
export $(xargs < ./env.test); node main.js;
and to access these variables in main.js
file
console.log(process.env.API_KEY);
more over, you most likely are usnig npm to manage your project so use package.json
scripts to ease your life
package.json
"scripts": {
"start:dev" : "export $(xargs < ./env.dev); node main.js;",
"start:test" : "export $(xargs < ./env.test); node main.js;
}
then you only do
npm run start:dev
in case you are using webpack
you can pass all env
variables inside configuration