-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.js
37 lines (33 loc) · 906 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
// Hierarchical node.js configuration with command-line arguments, environment
// variables, and files.
const nconf = module.exports = require('nconf');
const path = require('path');
nconf
// 1. Command-line arguments
.argv()
// 2. Environment variables
.env([
'NODE_ENV',
'PORT',
'GCLOUD_PROJECT',
'GOOGLE_APPLICATION_CREDENTIALS',
])
// 3. Config file
.file({ file: path.join(__dirname, 'config.json') })
// 4. Defaults
.defaults({
PORT: 8080,
// This is the id of your project in the Google Cloud Developers Console.
GCLOUD_PROJECT: '',
});
// Check for required settings
checkConfig('GCLOUD_PROJECT');
checkConfig('twitter');
checkConfig('bigquery');
checkConfig('storage');
function checkConfig (setting) {
if (!nconf.get(setting)) {
throw new Error(`You must set ${setting} as an environment variable or in config.json!`);
}
}