Categories
JavaScript Answers

How to set up environment specific configs to be used with everyauth with Node.js?

Spread the love

To set up environment specific configs to be used with everyauth with Node.js, we return the config according to the NODE_ENV environment variable.

For instance, we write

module.exports = () => {
  switch (process.env.NODE_ENV) {
    case "development":
      return {
        //...
      };
    case "production":
      return {
        //...
      };
    default:
      return {
        //...
      };
  }
};

in the config.js file to return the config according to the NODE_ENV environment variable value.

Then we write

const Config = require("./config");
const conf = Config();

to require the config.js file and then call the imported Config function to return the config for the environment in app.js.

And then we run

NODE_ENV=production node app.js

to set the NODE_ENV environment variable value and run app.js.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *