1.0.1 • Published 4 years ago

express-env-config v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

express-env-config

express-env-config is a middleware for handling different configurations in different environments for your front-end app served by express.js

Indeed, depending of an environment variable value, a GET request to your config will serve the right config file.

Exemple : if you set CURRENT_ENV to "staging", GET /appConfig.js will serve /staging.appConfig.js

Installation

npm install express-env-config

Usage

In your server.js file

const envConfig = require('express-env-config');
...
app.use(envConfig()); 

or using options (see below for option details)

const envConfig = require('express-env-config');
...
const options = {
  envVarName: 'MY_CURRENT_ENV',
  configFileName: 'conf.js' 
}
app.use(envConfig(options)); 

Options

Option nameDefault valueDescription
envVarNameCURRENT_ENVname of the environment variable to read in order to detect in wich environment the app is deployed
configFileNameappConfig.jsname of the config file your front-end app is fetching
configDirectory\/configname of the directory where all configs are stored

Test

npm test