Last active
June 9, 2016 15:33
-
-
Save evanshortiss/d240ca01fe0eba5f6aa4624a7c74f510 to your computer and use it in GitHub Desktop.
This file contains 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 express = require('express') | |
, async = require('async'); | |
var app = express(); | |
function getAges (callback) { | |
callback(null, ['23', '43']); | |
} | |
function getUsers (callback) { | |
callback(null, ['jane', 'john']); | |
} | |
function getData (callback) { | |
async.parallel({ | |
ages: getAges, | |
users: getUsers | |
}, callback); | |
} | |
app.get('/', function (req, res, next) { | |
function onData (err, data) { | |
if (err) { | |
res.status(500).json({ | |
msg: 'error' | |
}); | |
} else { | |
res.json(data); | |
} | |
} | |
getData(onData); | |
}); | |
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