'Does res.end() not ends the http.createServer() callback function?

I have question about res.end() method available with require("http).createServer(). So the tutorial I was watching the following worked:

require("http").createServer((req, res) => {
  if (req.url === "/") {
    res.end("Here is home Page");
  }
  if (req.url === "/about") {
    res.end("Here is about page");
  }
  res.end("404 Page not found");
}).listen(8080);

But when I try to run the snippet it give the following error:

ERR_STREAM_WRITE_AFTER_END

I know why this is happening. My question is why res.end() is not stopping the createServer() callback. If you know please give some advice.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source