Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nconf = module.exports = require('nconf');
- const path = require('path');
- nconf
- // 1. Command-line arguments
- .argv()
- // 2. Environment variables
- .env([
- 'DATA_BACKEND',
- 'GCLOUD_PROJECT',
- 'MYSQL_USER',
- 'MYSQL_PASSWORD',
- 'MYSQL_HOST',
- 'PORT',
- 'INSTANCE_CONNECTION_NAME',
- 'NODE_ENV'
- ])
- // 3. Config file
- .file({ file: path.join(__dirname, 'config.json') })
- // 4. Defaults
- .defaults({
- // dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
- // configure the appropriate settings for each storage engine below.
- // If you are unsure, use datastore as it requires no additional
- // configuration.
- DATA_BACKEND: 'cloudsql',
- // This is the id of your project in the Google Cloud Developers Console.
- GCLOUD_PROJECT: 'bookingsystem2',
- MYSQL_USER: 'my user',
- MYSQL_PASSWORD: 'my password',
- MYSQL_HOST: 'sql ip address',
- PORT: 3306,
- INSTANCE_CONNECTION_NAME: 'my ICN',
- NODE_ENV: 'production'
- });
- // Check for required settings
- checkConfig('GCLOUD_PROJECT');
- if (nconf.get('DATA_BACKEND') === 'cloudsql') {
- checkConfig('MYSQL_USER');
- checkConfig('MYSQL_PASSWORD');
- if (nconf.get('NODE_ENV') === 'production') {
- checkConfig('INSTANCE_CONNECTION_NAME');
- }
- }
- function checkConfig (setting) {
- if (!nconf.get(setting)) {
- throw new Error('You must set ' + setting + ' as an environment variable or in config.json!');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement