Last active
June 9, 2016 14:44
-
-
Save evanshortiss/b793361611bd52e8d389ad0a6dbe44eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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