Created
April 5, 2015 02:24
-
-
Save JustinMorgan/c1ae74b9f86cf2672e1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require("mongoose"), | |
connection = mongoose.connection, | |
gracefulExit = function() { | |
connection.close(function() { | |
console.log('Mongoose default connection disconnected through app termination'); | |
process.exit(0); | |
}); | |
}; | |
mongoose.connect(process.env.MONGO_URI); | |
connection.on('error', function(err) { | |
console.error('DB connection error', err); | |
}).once('open', function() { | |
console.log('DB open'); | |
}); | |
process.on('SIGINT', gracefulExit) | |
.on('SIGTERM', gracefulExit); | |
module.exports = function(name, dataStructure) { | |
var schema = new Schema(dataStructure); | |
return mongoose.model(name, schema); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment