I'm wondering what the mechanics behind the behaviour of the following code are:
res.send(200, { data: 'test data' });
console.log('still here...');
My understanding is that res.send
doesn't return the function, but does close the connection / end the request. This could explain why I can still execute code after a res.send
command (I looked through the express source and it doesn't seem to be an asynchronous function).
Is there something else at play that I may be missing?
send
it just pipes data out the http connection and your code continues. you can just usereturn
if you want to terminate the code, or just not write anything else. sorry for misinterpretation.