-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.js
41 lines (37 loc) · 1.07 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
'use strict'
var mongoose = require('mongoose')
// replace this "localhost" value with the one from heroku/mlab
var url = 'mongodb://brenda00zhao:631129@ds129651.mlab.com:29651/rrhw8final'
mongoose.connect(url)
///////////////////////////////////////////////////
mongoose.connection.on('connected', function() {
console.log('Mongoose connected to ' + url)
})
mongoose.connection.on('error', function(err) {
console.error('Mongoose connection error: ' + err)
})
mongoose.connection.on('disconnected', function() {
console.log('Mongoose disconnected')
})
process.once('SIGUSR2', function() {
shutdown('nodemon restart', function() {
process.kill(process.pid, 'SIGUSR2')
})
})
process.on('SIGINT', function() {
shutdown('app termination', function() {
process.exit(0)
})
})
process.on('SIGTERM', function() {
shutdown('Heroku app shutdown', function() {
process.exit(0)
})
})
function shutdown(msg, callback) {
mongoose.connection.close(function() {
console.log('Mongoose disconnected through ' + msg)
callback()
})
}
///////////////////////////////////////////////////