Because NodeJS is non-blocking, you might be running code that wasn't intended. This is why return statements are important in your code. It's a simple mistake that many developers can make when transitioning to NodeJS from a different language.

Let's say you have an endpoint like the one below...

// A Typical ExpressJS Endpoint
app.get('/people/:person', function(req, res) {  
  Database.getPerson(req.params.person, function(err, result) {
    if (err) {
      res.status(500).json({
        error: err.message
      });
    }

    res.status(200).json(result);
  });
});

In the code above, we have an endpoint that grabs a person from a database. If an error occurs in our getPerson call, we return some JSON with the error message.

The problem with this code is that the script does not stop processing when we return the error message. Because we did not use a return statement in our code, the code below the if block will still execute.

This is better...

// A Typical ExpressJS Endpoint
app.get('/people/:person', function(req, res) {  
  Database.getPerson(req.params.person, function(err, result) {
    if (err) {
      return res.status(500).json({
        error: err.message
      });
    }

    return res.status(200).json(result);
  });
});

Adding that return statement will stop the rest of the script from executing after returning a response.