Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. // import mongoose and connect to mongoDB
  2. const mongoose = require('mongoose')
  3. mongoose.connect('mongodb://localhost/restaurant', { useNewUrlParser: true })
  4. const db = mongoose.connection
  5.  
  6. // actions if connect error
  7. db.on('err', (err) => {
  8. if (err) return console.error(err)
  9. })
  10.  
  11. // actions if connect success
  12. db.once('open', (err) => {
  13. if (err) return console.error(err)
  14. console.log('connect to mongoDB successifully !')
  15. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement