Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // default.json
  2.  
  3. {
  4. "mongoURI":
  5. "mongodb+srv://mern123:<password>@mernatoz-9kdpd.mongodb.net/test?retryWrites=true&w=majority"
  6. }
  7. /* Replace <password> with your database password */
  8.  
  9. /* ------------------------------------------------------------------ */
  10. // db.js
  11.  
  12. const mongoose = require('mongoose');
  13. const config = require('config');
  14. const db = config.get('mongoURI');
  15.  
  16. const connectDB = async () => {
  17. try {
  18. await mongoose.connect(
  19. db,
  20. {
  21. useNewUrlparser: true
  22. }
  23. );
  24.  
  25. console.log('MongoDB is Connected...');
  26. } catch (err) {
  27. console.error(err.message);
  28. process.exit(1);
  29. }
  30. };
  31.  
  32. module.exports = connectDB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement