Skip to content

Instantly share code, notes, and snippets.

@evanshortiss
Last active June 9, 2016 14:44
Show Gist options
  • Save evanshortiss/b793361611bd52e8d389ad0a6dbe44eb to your computer and use it in GitHub Desktop.
Save evanshortiss/b793361611bd52e8d389ad0a6dbe44eb to your computer and use it in GitHub Desktop.
'use strict';
var Promise = require('bluebird')
, express = require('express');
var app = express();
function getUsers () {
return new Promise(function (resolve, reject) {
resolve(['jane', 'john']);
});
}
function getAges () {
return new Promise(function (resolve, reject) {
resolve(['23', '43']);
});
}
function getData () {
return Promise.props({
users: getUsers(),
ages: getAges()
});
}
app.get('/', function (req, res, next) {
getData()
.then(function (data) {
res.json(data);
})
.catch(next);
});
app.listen(3001, function (err) {
if (err) {
throw err;
}
console.log('listening on 3001');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment