So, I have some node code to deal with and I’m hoping someone here can help me refactor it. This is express + pg:
app.get('/path', function (req, res, next) {
pg.connect(connectionString, function(err, client, releaseClientToPool) {
client.query(query, function(err, data) {
if(err) {
res.send(tellFrontEndThereIsAnError);
} else {
res.send(tellFrontEndYay);
}
releaseClientToPool);
});
});
});
I want to extract the part that runs the query, that is, basically everything inside the express controller action. Except of course, nested inside the callbacks, is express code. How would you refactor this?