1.6.0 • Published 6 years ago

mongo-express-middleware v1.6.0

Weekly downloads
2
License
MIT
Repository
gitlab
Last release
6 years ago

Mongo CRUD middleware for express.

Installation

This is a Node.js module available through the npm registry.

Before installing, make sure that your application use express and mongoose.

Installation is done using the npm install command:

$ npm install mongo-express-middleware

or yarn add command:

$ yarn add mongo-express-middleware

Using

app.js

import express from 'express';
import { mongoMiddleware } from 'mongo-express-middleware';

const app = express();

app.use('/api/path', mongoMiddleware(options: Object));

Current midlleware works with list path <host>/api/path/ and entity path <host>/api/path/:id([a-zA-Z0-9]+)

Middleware options include multiple keys

{
  /*
    Model field set mongoose model.
    Required field.
  */
  model: Object,
  /*
    Fields specify the behavior of the middleware according express docs
    http://expressjs.com/en/api.html#express.router
  */
  mergeParams: boolean,
  strict: boolean,
  caseSensitive: boolean,
  /*
    Callback for handle returned data.

    * create, read methods work with entity list
    * readEntity, put, delete methods work with single entity

    Default callback

    function(req, res, next) {
      res.status(200).send(res.data);
    }
  */
  create: Function,
  read: Function,
  readEntity: Function,
  update: Function,
  delete: Function,
}

Example

Application

Run tests using the command yarn test

License

MIT

1.6.0

6 years ago

1.5.0

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago