1.6.0 • Published 6 years ago
mongo-express-middleware v1.6.0
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
Run tests using the command yarn test