In express and node a return a json and after i call end.
Is necessary to call
res.end()
after
res.json()
?
send() (and remember, res. json() ) both allow us to send some data and they also end the response, so there's no need to explicitly call res.
If the current middleware function does not end the request-response cycle, it must call next() to pass control to the next middleware function. Otherwise, the request will be left hanging. An Express application can use the following types of middleware: Application-level middleware.
end() Function. The res. end() function is used to end the response process. This method actually comes from the Node core, specifically the response.
res. send() or res. json() should end all writing to the response stream and send the response. However, you absolutely can call next() if you want to do further processing after the response is sent, just make sure you don't write to the response stream after you call res.
You don't have to call res.end()
if you call res.json()
. res.json()
calls res.end()
for you.
Example from docs; https://expressjs.com/en/api.html
You do not need.
No, it's not necessary to call res.end()
after you have called res.json()
(or res.send()
or res.render()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With