challenge step 3 - success path

The last case is the happy path, the success case, when everything goes as planned. The ID is valid and we find a document in the Todos collection that has an ID matching the ID passed in. In that case all we're going to do is respond using res.send, sending back the Todo. Now, you could have sent it in like res.todo(todo); this will indeed work, but what I want to do is tweak it just a little bit. Instead of sending back Todo as the body, I'm going to send back an object where the Todo is attached as the todo property using the ES6 object definition, which is identical to this:

res.send({todo: todo});

This gives me a little flexibility down the line. I could always add other properties onto the response, like ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.