Async/Await & Express, Mocha etc.
Express.js Examples:
app.get('/authors', async (req, res) => {
res.json(await model.getAuthors())
});app.get('/health', async (req, res) => {
const someParam = req.header("someParam");
const check = await model.healthCheck(someParam);
if (!check) {
res.send(500, "Internal Server Error");
} else {
res.send(200, "OK");
}
});Mocha Example:
const http = require('superagent');
describe('Get Authors', () => {
it('Success', async () => {
const params = {
// ... something
};
const response = await http.get('/authors', params);
assert.ok(response);
});
});Last updated