0

For managing python, I maintain multiple environments using conda.

i.e. for a new project, I create a new environment new-project for my new python project.

conda create -n new-project python=3.8

However, it is not clear to me how I can create new node environemnt for my different nodejs projects.

1

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.