-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
34 lines (28 loc) · 900 Bytes
/
database.js
File metadata and controls
34 lines (28 loc) · 900 Bytes
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
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/nodeSample');
// Log error if not connected
mongoose.connection.on('error', console.error.bind(console, 'Connection error.'));
// Log status if connected to database
mongoose.connection.once('open', function() {
// we're connected!
console.log("Connected to database.")
});
/** Global object for this module */
var db = {};
/** Define user schema */
var userSchema = new mongoose.Schema({
name: String,
email: String,
active: {
type: Boolean,
default: false
},
created: {
type: Date,
default: Date.now
}
});
/** Tie schema to mongoose model and add it to global object*/
db.User = mongoose.model('User', userSchema);
/** Export global database object */
module.exports = db;