Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminate ExpressJS request

How would I end an Express 3 request? res.end() certainly doesn't stop the processing.

exports.home = function(req, res) {
  res.end();
  console.log('Still going, going...');
like image 358
cyberwombat Avatar asked Apr 06 '13 02:04

cyberwombat


1 Answers

You'll need to return. E.g.,

exports.home = function(req, res) {
  return res.end();
  console.log('I will never run...');

res.end() simply completes and flushes the response to the client. Just like any other action, however, that doesn't tell JavaScript to stop running so we need to explicitly return out of the function (although I might ask the question of why you would have code after flushing the response that you don't actually want to run...?).

like image 118
jmar777 Avatar answered Sep 17 '22 13:09

jmar777