title: Using Promises in Mongoose Routes
body: <p>I understand Promises in JavaScript or atleast I think I do (correct me if Im wrong).</p>
  
  <p><strong>Create a Promise:</strong></p>
  
  <pre><code>var promise = new Promise(function(resolve, reject){
    // do something async here
  
    if(itWorked){
  
      resolve();
  
    }else {
  
      reject();
    }
  
  });
  </code></pre>
  
  <p><strong>Use a Promise:</strong></p>
  
  <pre><code>promise.then(function(result){
  
  },function(err){
  
  });
  </code></pre>
  
  <p>I have an app based on MEAN Stack and some of my mongoose routes are becoming a callback hell. I want move away from callbacks in mongoose routes and handle them using Promises. But I can't seem to figure out how exactly to do that. </p>
  
  <p><strong>For example:</strong></p>
  
  <pre><code>app.get('/users', function(req, res){
  
    User.findOne(_id, function(err, user){
        if(err)
           console.log(err)
        else if(user){
  
           Receipt.findOne(user.bookName, function(err, book){
             if(err)
              console.log(err)
  
             else if(book){
               // again do something here
            }  
         })
       }
     })
  });
  </code></pre>
  
  <p><strong>In the above example you can see that the code is getting harder to read and maintain. How can I use Promises here to improve my code?</strong> </p>