Created
January 5, 2020 16:19
-
-
Save PatrickKalkman/4449f6bb9e477fdf9acfe92fc090bce6 to your computer and use it in GitHub Desktop.
Configuration structure for Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create and export configuration variables used by the API | |
* | |
*/ | |
const constants = require('./constants'); | |
// Container for all environments | |
const environments = {}; | |
environments.production = { | |
httpPort: 3000, | |
host: process.env.HOST || '0.0.0.0', | |
envName: 'production', | |
log: { | |
level: constants.LOG_LEVELS.DEBUG, | |
}, | |
database: { | |
url: 'mongodb://localhost:27017/workflow-db', | |
name: 'workflow-db', | |
connectRetry: 5, // seconds | |
}, | |
workflow: { | |
pollingInterval: 10, // Seconds | |
}, | |
}; | |
// Determine which environment was passed as a command-line argument | |
const currentEnvironment = typeof process.env.NODE_ENV === 'string' ? process.env.NODE_ENV.toLowerCase() : ''; | |
// Check that the current environment is one of the environment defined above, | |
// if not default to prodution | |
const environmentToExport = typeof environments[currentEnvironment] === 'object' ? environments[currentEnvironment] : environments.production; | |
// export the module | |
module.exports = environmentToExport; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment