Skip to content
Advertisement

In Express.js, should I return response or not?

For Express.js 4.x I can’t find wether I should return the response (or next function) or not, so:

This:

app.get('/url', (req, res) => {
    res.send(200, { message: 'ok' });
});

Or this:

app.get('/url', (req, res) => {
    return res.send(200, { message: 'ok' });
});

And what is the difference?

Advertisement

Answer

You don’t. The (req, res) signature tells express this is the last function in the chain, and it does not expect a return value from this function. You can add a return statement, but it won’t “do anything”, beyond the JS engine performing some additional (but meaningless) overhead.

Advertisement