node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org »


CRUD for express using mongoose


If you need a module, to extend express to perform CRUD operations using mongoose this module, do that in this way...


First of all you need to install the module using npm:

[sudo] npm i [--save] express-mongoose-crud


In you application you need to call:

var crud = require('express-mongoose-crud');

And pass the mongoose reference to the function after your definitions, or compilation of you models, just depends on you was defined it.

crud = crud({ mongoose: mongoose });

After that, you be able to perform this:

Create'/:entity', crud, function (req, res) {

The :entity is required, because i use to find your model. Now to read that is easy...


router.get('/:entity/:id', crud, function (req, res) {

If you have noted, with req.params.entity you be able to retrieve the content of res.locals, with the name of your entity. In that way you can re-use in views if configure your application to do that.


And if you need a list a bunch of data related to an entity that is the path to do this operation:

router.get('/:entity', crud, function (req, res) {

Now you have an array in locals realted to entity.


And of course to update data:

router.put('/:entity/:id', crud, function (req, res) {


Finally the remove operation:

router.delete('/:entity/:id', crud, function (req, res) {


All operations is surrounded by the http method, but you can do with some changes the with special param action, for example:'/:entity/:action', crud, function () {

When you pull the trigger for example to /product/create with some content who match with schema the results appear, with agreements of you code block inside the route function.

Created by

Kaique da Silva under ICS license.

Development mode

Some changes are coming to this module, use with caution!

To contribute with this module is easy, just put things inside your enviroment of development.

git clone git://[your-user]/express-mongoose-crud.git


git clone

Install the development dependencies:

[sudo] npm i

Run the tests using npm test, before check if you has installed globally the mocha, if you not... just do that:

[sudo] npm i -g mocha

The tree structure was listed below:

  • lib - constains the lib files who deals with the logic of operations
  • index.js - contains the crud definitions and middleware setup
  • test - has the test of the lib and an test of the middleware with a case
  • - A brief explanation about this module, if something new appears the first place who you fina some resource is here
  • package.json - Default

Sorry about any type error and issues are welcome, see you soon xox!