node.jsexpress

Express: Do not send response to request


Is it somehow possible in Express to not respond at all? I don’t want to send a 4xx or 5xx in a specific case, but just show the “server did not respond” error (in Chrome it’s the ERR_EMPTY_RESPONSE).

router.get('/noresponse', (req, res, next) => {
  res.end(); // this will send an empty page with a 200 status
});

To clarify: I want a behavior similar to NGINX when “sending” a 444 status. (which does not actually send a 444 to the client, but cancels the request)


Solution

  • For the sake of completeness, here’s a snippet which does what I was initially aiming for:

    router.get('/noresponse', (req, res, next) => {
      res.destroy(null);
    });
    

    However as I find no documentation about its implications and I do not want to work against any best practices I’ll go for a 4xx response instead.