O'Reilly logo

Express.js Blueprints by Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Update route

A CRUD API is not complete with the update route! If you are a Hacker News frequenter, you'll know that titles of the submissions can change (but not the URL). This route should be straightforward, but there is one caveat! Yes, you could use findByIdAndUpdate, which is used by upvote, but what if you wanted to use Mongoose's instance method .save()?

Well, it does not return a Promise, so therefore we cannot yield to it. In fact, at the time of writing, there is still an open issue about this. Using save(), we can only use the traditional callback pattern. However, remember the rule—do not mix generator functions with callbacks!

So now what? Well, it will be quite common for certain node modules to be only available in the callback format. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required