Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import mongoose and connect to mongoDB
- const mongoose = require('mongoose')
- mongoose.connect('mongodb://localhost/restaurant', { useNewUrlParser: true })
- const db = mongoose.connection
- // actions if connect error
- db.on('err', (err) => {
- if (err) return console.error(err)
- })
- // actions if connect success
- db.once('open', (err) => {
- if (err) return console.error(err)
- console.log('connect to mongoDB successifully !')
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement