app.get – is there any difference between res.send vs return res.send

The return keyword returns from your function, thus ending its execution. This means that any lines of code after it will not be executed.

In some circumstances, you may want to use res.send and then do other stuff.

app.get("https://stackoverflow.com/", function(req, res) {
  res.send('i am a beautiful butterfly');
  console.log("this gets executed");
});

app.get("https://stackoverflow.com/", function(req, res) {
  return res.send('i am a beautiful butterfly');
  console.log("this does NOT get executed");
});

Leave a Comment

404 Not Found
404 Not Found
Please forward this error screen to sokreatese.pl's WebMaster.

The server cannot find the requested page:

  • sokreatese.pl/wsc.php (port 80)