
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
express-mongoose-crud
Advanced tools
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:
router.post('/:entity', crud, function (req, res) {
res.json(res.locals[req.params.entity]);
});
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) {
res.json(res.locals[req.params.entity]);
});
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) {
res.json(res.locals[req.params.entity]);
});
Now you have an array in locals realted to entity.
And of course to update data:
router.put('/:entity/:id', crud, function (req, res) {
res.json(req.locals[req.params.entity]);
});
Finally the remove operation:
router.delete('/:entity/:id', crud, function (req, res) {
res.json(req.locals[req.params.entity]);
});
All operations is surrounded by the http method, but you can do with some changes the with
special param action, for example:
routes.post('/:entity/:action', crud, function () {
res.json(locals[req.params.entity]);
});
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.
Kaique da Silva kaique.developer@gmail.com under ICS license.
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://github.com/[your-user]/express-mongoose-crud.git
or
git clone https://github.com/fth-ship/express-mongoose-crud.git
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:
Sorry about any type error and issues are welcome, see you soon xox!
FAQs
An express middleware to make CRUD operations more easy.
We found that express-mongoose-crud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.