Middlewares for your API Server - 401-advanced-javascript-aimurphy/seattle-javascript-401n13 GitHub Wiki
Express Router: router.param(name, callback)
.param method adds callback triggers to route parameters, where name is the name of the parameter and callback is the callback function (req, res, next, id).
- req, the request object.
- res, the response object.
- next, indicating the next middleware function.
- The value of the name parameter.
- The name of the parameter.
The 4 types of Mongoose Middlewares
- document, model, aggregate & query
In document middleware functions, this
refers to the document.
- validate
- save
- remove
- init (note: init hooks are synchronous)
Model middleware is supported for the following model functions. In model middleware functions, this
refers to the model.
- insertMany
Aggregate middleware is for MyModel.aggregate(). Aggregate middleware executes when you call exec() on an aggregate object. In aggregate middleware, this
refers to the aggregation object.
- aggregate
The following are model AND query functions. In query middleware functions, this
refers to the query.
- count
- deleteMany
- deleteOne
- find
- findOne
- findOneAndDelete
- findOneAndRemove
- findOneAndUpdate
- remove
- update
- updateOne
- updateMany
to be continued
sources: