Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Last active June 27, 2019 16:30
Show Gist options
  • Save barmgeat/2f55a2eae6675543b83fc5f8de80fafc to your computer and use it in GitHub Desktop.
Save barmgeat/2f55a2eae6675543b83fc5f8de80fafc to your computer and use it in GitHub Desktop.
connect to mongo database from node server
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