I am trying to integrate promises in the API of the application that I am developing. I get "No data" in Postman from the following route, while the comment block works just fine.
import User from './models/User';
import express from 'express';
import Promise from 'bluebird';
const router = express.Router();
router.get("/", function(req, res, next){
Promise.try(function(){
User.find({}, function(err, users) {
return Promise.resolve(users);
});
}).then(function(result){
if (result instanceof Function) {
result(res);
} else {
return res.json(result);
}
}).catch(function(err){
next(err);
});
});
module.exports = router;
source
share