Skip to content

Build for more environments such as staging #15065

Discussion options

You must be logged in to vote

What I do in my projects when I need different environments is the following:

I firstly like to create a variables folder in the project root, after which I create a parser.js file with this content:

const dotenv = require('dotenv');

const files = {
  ...dotenv.config({ path: 'variables/.env' }).parsed,
  ...dotenv.config({ path: `variables/.env.${process.env.ENVIRONMENT}` }).parsed,
  ...dotenv.config({ path: `variables/.env.${process.env.ENVIRONMENT}.local` }).parsed,
};

module.exports = () => {
  Object.keys(files, (key) => {
    if (typeof files[key] !== 'string') {
      files[key] = JSON.stringify(files[key]);
    }
  });
  return files;
};

As you see, it requires dotenv, so you n…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@hamidhosseini
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by metalsadman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants