Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created January 5, 2020 16:19
Show Gist options
  • Save PatrickKalkman/4449f6bb9e477fdf9acfe92fc090bce6 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/4449f6bb9e477fdf9acfe92fc090bce6 to your computer and use it in GitHub Desktop.
Configuration structure for Node.js
/*
* 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