[Fixed] 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:


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?


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 don’t "do anything", beyond the JS engine performing some additional (but meaningless) overhead.

Leave a Reply

(*) Required, Your email will not be published