-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
73 lines (51 loc) · 1.77 KB
/
setup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
console.log('Running subscript')
const mongoose = require('mongoose')
const dotenv = require('dotenv')
let config = require('config'); //we load the db location from the JSON files
function getEnvFile(nodeEnv){
if (process.env.NODE_ENV==="test"){
return ".env.test"
}else{
return ".env"
}
}
function GetConfigDetailsAndConnect(){
var envFile = getEnvFile(process.env.NODE_ENV)
dotenv.config({path: envFile})
console.log('Running "' + config.util.getEnv('NODE_ENV') + '" environment')
let dbHost = config.get('dbConfig.host')
let port = config.get('dbConfig.port')
console.log(config.get('dataAPI.url'))
mongoose.connect(dbHost, {
useNewUrlParser: true,
useUnifiedTopology: true
})
const db = mongoose.connection;
db.once("open", (_) => {
console.log("Database connected:", dbHost);
});
return db;
}
module.exports= GetConfigDetailsAndConnect
//=------------------------------
//=------------------------------
//=------------------------------
//=------------------------------
// If want to make into command line script with flags
// Allowing command line arguments
// --env indicates which environment you are running the migration for
// The options should be
//const { exit } = require('yargs')
// const yargs = require('yargs');
// var argv = require('yargs/yargs')(process.argv.slice(2))
// .usage('Usage: $0 <command> [options]')
// .command('migrate', 'Migrate db to contain live featur in forms')
// .alias('e', 'env')
// .default('env', "dev")
// .describe('e', 'The environment you are working with')
// .alias('h', 'help')
// .demandOption(['env'])
// .help('h')
// .argv;
// console.log("Node Environment:")
// console.log(argv.env);