Kevin.a
Kevin.a

Reputation: 4286

Enviroment variables in node application

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?

Upvotes: 0

Views: 41

Answers (1)

terrymorse
terrymorse

Reputation: 7086

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;
    }

Upvotes: 1

Related Questions