Last active
June 27, 2019 16:30
-
-
Save barmgeat/2f55a2eae6675543b83fc5f8de80fafc to your computer and use it in GitHub Desktop.
connect to mongo database from node server
This file contains hidden or 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
const mongoose = require('mongoose'); | |
mongoose.connect( | |
'mongodb://username:password@host/databasename', {useNewUrlParser: true} | |
); | |
const db = mongoose.connection; | |
db.on('error', console.error.bind(console, 'connection error:')); | |
db.once('open', function () { | |
console.log("you are connected to the database") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment