O'Reilly logo

RESTful Web API Design with Node.js - Second Edition by Valentin Bojinov

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

Creating a user-defined model around a Mongoose model

After seeing how a model works, it is time to create a user-defined module, called conctactdataservice, which wraps all CRUD operations for a contact. Since we intend to use that module in a RESTful web application, it seems logical to leave the schema definition and the model creation outside the module and have them provided as arguments of each module function. For now, the module will provide an implementation for each CRUD function, starting with a remove() function. It looks up a contact based on its primary contact number and deletes it from the database, if it exists:

exports.remove = function (model, _primarycontactnumber, response) { console.log('Deleting contact with primary number: ...

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