Skip to content

Commit

Permalink
Added MongoDB connection code via Mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
wwongandy committed Jan 17, 2020
1 parent 0ca28ea commit 18be082
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

# MongoDB Connectivity Credentials
mongodb-connectivity-uri.js
9 changes: 9 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ SwaggerExpress.create(config, function(err, swaggerExpress) {
console.log('try this:\ncurl http://127.0.0.1:' + port + '/authentication?name=Scott');
}
});

// Using Mongoose to blackbox the MongoDB connectivity
const secretURI = require('./mongodb-connectivity-uri');
const mongoose = require('mongoose');
mongoose.connect(secretURI, { useNewUrlParser: true });

const db = mongoose.connection;
db.on('error', (err) => console.log(`Connection error:\n${err}`));
db.once('open', () => console.log(`Connected to ${db.name}.`));

0 comments on commit 18be082

Please sign in to comment.