title: How to resolve UnhandledPromiseRejectionWarning in mongoose?
body: <p>I'm trying to fetch data using mongoose.</p>
  
  <p>So everytime i got to fetch the posts from the api -- localhost:3000/api/posts -- i get the foll error that i am unable to decypher.</p>
  
  <blockquote>
    <p>(node:12100) UnhandledPromiseRejectionWarning: Unhandled promise
    rejection (r<br>
    ejection id: 1): [MongoError: connect ETIMEDOUT xxxx]</p>
  </blockquote>
  
  <p>The foll is my code in the api.js file. I'd appreciate if you can provide guidance on where i am going wrong with this.</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const mongoose = require('mongoose');
  const post = require('../models/post');
  
  const db = "mongodb://&lt;dbuser&gt;:&lt;dbpassword&gt;@xxxxxxx.mlab.com:xxxxxx/xxxxxx";
  
  mongoose.Promise = global.Promise;
  mongoose.connect(db, function(err) {
      if(err) {
          console.log('Connection error');
      }
  });
  
  router.get('/posts', function(req, res) {
      console.log('Requesting posts');
      post.find({})
          .exec(function(err, posts) {
              if (err) {
                  console.log('Error getting the posts');
              } else {
                  res.json(posts);
                  console.log(posts);
              }
          });
  });
  //in order for server.js file to access the api, we have to add the foll line
  module.exports = router;
  </code></pre>
  
  <p>May 23, 2017</p>
  
  <p>Now i'm also getting deprecation warning when in fact i have included the foll loc:</p>
  
  <pre><code>mongoose.Promise = global.Promise; //we add this because if we dont, you may get a warning that mongoose's default promise library is deprecated
  </code></pre>
  
  <p>I'd appreciate if i can get some guidance with this issue. Thanks</p>