0

while developing my app i've been using the dotenv package to fake enviroment variables.

require('dotenv').config({path : '../../../config/.env'});
const jwtSecret = process.env.JWT_SECRET; 

What will happen when i push to my live server with these? How will I handle the enviroment variables then?

1 Answer 1

1

Here's what I would do:

On the production server only, set an environment variable named ENV_PRODUCTION. Then check for it.

    // save current environment
    const saveEnv = process.env;

    // load local environment
    require('dotenv').config({path : '../../../config/.env'});

    // restore production environment
    if (process.env.ENV_PRODUCTION) {
      process.env = saveEnv;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.