/
db.js
30 lines (25 loc) · 849 Bytes
/
db.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
const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost:27017/ciphertrick"; //connecting to ciphertrick
const options = {
keepAlive: true,
keepAliveInitialDelay: 300000,
useNewUrlParser: true
};
mongoose.connect(mongoURI, options);
mongoose.connection.on('connected', ()=>{
console.log('Mongoose default connection open to ' + mongoURI);
});
// If the connection throws an error
mongoose.connection.on('error', (err)=>{
console.log('handle mongo errored connections: ' + err);
});
// When the connection is disconnected
mongoose.connection.on('disconnected', ()=>{
console.log('Mongoose default connection disconnected');
});
process.on('SIGINT', ()=>{
mongoose.connection.close(()=>{
console.log('App terminated, closing mongo connections');
process.exit(0);
});
});