I think:
app.get('/thing', function (req, res) {
try {
await user = db.get({user: req.user});
res.send({user:user});
} catch {
res.send(400);
}
});
beats the hell out of: app.get('/thing', function (req, res) {
db.get({user: req.user}, function (err, user) {
if (err) return res.send(400);
res.send({user:user});
});
});
especially when you have conditionals or loops that can look like: if (user.name == 'abc') {
resp = 5;
} else {
await resp = db.get_resp({user:user});
}
await db.save(something);
I suppose it doesn't get rid of callbacks, just makes them readable.