-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (38 loc) · 1.21 KB
/
app.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
/**
* Created by vamsee on 5/19/17.
*/
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var log4js = require('log4js');
var log = log4js.getLogger('apps');
const credController = require("./controllers/credential");
const Event = require("./models/Event");
(async () => {
// initialize CredStash with KMS secrets via AWS SDK
await credController.initCreds()
if (mongoose.connection.readyState === 0) {
await mongoose.connect(process.env.MONGO_URL, {
server: {auto_reconnect: true, reconnectInterval: 1000, reconnectTries: Number.MAX_VALUE}
})
}
mongoose.connection.once('open', function () {
log.info("app.js: Mongo DB connection established via mongoose")
});
mongoose.connection.on('error', function () {
log.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
process.exit(1);
});
// confirm we can save a mongoose mapped object to Mongo
let event = new Event({
name: "Test2",
description: "Test2 Description",
liveEvent: true,
appId: "com.onkore.Test2",
})
await event.save()
const events = await Event.find();
log.info(events)
process.exit(0);
})().catch(err => {
log.error(err.stack)
})