Back to our routing

With the Picture model available to us, we can populate it directly from inside our add route. The request body contains the same parameters as our schema, so the mapping is invisible to us. When it has been populated, we call the save method. If there's an error, we will send this back to the client; otherwise, we are going to send the picture back to the client:

const picture = new Picture(request.body);picture.save((err, picture) => {  if (err) {    response.send(err);  }  response.json(picture);});
In production applications, we wouldn't really want to send the error back to the client as that exposes the inner workings of our application. With a small application, intended for our own use only, it is less of an issue and ...

Get Advanced TypeScript Programming Projects 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.