Edit: I no longer do what is explained below, since you should not return a value when this is not necessary. This makes your code less readable and looks hacked. Instead, I suggest separating the return statement from res.send() . @slavafomin explained this well in the comments.
An easy way to stop the execution of a function and send a response at one time is
return res.send('500', 'Error message here');
This allows you to use short if to handle errors such as:
if (err) { return res.send('500', 'Error message here'); }
The exact return of the res.send function is an object that seems to contain the entire state of the connection after it has ended (request, status, headers, etc.), but this should not matter, since you wonβt do anything with it .
marcospgp Jul 30 '14 at 13:37 2014-07-30 13:37
source share