Permalink
Browse files

Connect ExpressJS to MongoDB

  • Loading branch information...
amejiarosario committed Aug 6, 2016
1 parent c6eb4d7 commit 948a32391d208dd1303d67b443456a377e93fb8d
Showing with 11 additions and 0 deletions.
  1. +11 −0 app.js
View
11 app.js
@@ -8,6 +8,17 @@ var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
+// load mongoose package
+var mongoose = require('mongoose');
+
+// Use native Node promises
+mongoose.Promise = global.Promise;
+
+// connect to MongoDB
+mongoose.connect('mongodb://localhost/todo-api')
+ .then(() => console.log('connection succesful'))
+ .catch((err) => console.error(err));
+
var app = express();
// view engine setup

0 comments on commit 948a323

Please sign in to comment.