npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-mongoose-crud

v0.0.1

Published

An express middleware to make CRUD operations more easy.

Downloads

2

Readme

CRUD for express using mongoose

Description

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

Installation

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

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

Usage

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

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...

Read

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.

List

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.

Update

And of course to update data:

router.put('/:entity/:id', crud, function (req, res) {
  res.json(req.locals[req.params.entity]);
});

Remove

Finally the remove operation:

router.delete('/:entity/:id', crud, function (req, res) {
  res.json(req.locals[req.params.entity]);
});

Notes

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.

Created by

Kaique da Silva [email protected] 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://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:

  • 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
  • README.md - 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!