Skip to content

Instantly share code, notes, and snippets.

@mhemrg
Last active February 10, 2019 09:46
Show Gist options
  • Save mhemrg/08a0f4d918deb1048dee983389ed5d74 to your computer and use it in GitHub Desktop.
Save mhemrg/08a0f4d918deb1048dee983389ed5d74 to your computer and use it in GitHub Desktop.
Connect to MongoDB in NodeJS with Mongoose | Liara
const mongoose = require('mongoose');
mongoose.connect('mongodb://root:[email protected]:PORT/cats_db', {
useNewUrlParser: true,
authSource: 'admin',
});
const Cat = mongoose.model('Cat', { name: String });
const kitty = new Cat({ name: 'Kitty' });
kitty.save().then(() => console.log('Cat added.'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment