Filter heroku logs and retain the color.
Extremely opinionated resource middleware for express and mongoDB.
For the specific use case where you want to provide view, validator, and persistence middleware for a resource.
This was created to save time when implementing a long multi-step form process.
easily provide resources for a form:
var app = express;var viewPath = 'form';var selectOptions = 'Yes' 'No' 'Maybe';var fc =viewPathviewPathfieldtype: 'select' name: 'testField' options: selectOptionsvalidatorfn: 'notEmpty' param: 'testField' msg: 'Test field cannot be empty'validatorfn: 'isIn' param: 'testField' msg: 'Valid option required' selectOptionssave'testField' return reqtestObjnext return resredirect'/' + savedObjid;var m = fcmiddleware;appget'/' mrender;apppost'/' mvalidateAndSave;
var FormMiddleware = require'express-mongodb-form-middleware';
Create a new
The returned object
fm is a
viewPath to location of the view on disk.
Add a field that can be passed to the view, validated, and/or saved.
opts.locals would be any properties the view might use.
Field that get's created has a
getViewOpts method that returns all the assigned locals along with the
Validate a field. Uses node-validator validators.
Updates the property on the object with the given
field can be an array of field names.
fn is a function that returns the object on which
field is to be updated.
req, res as parameters.
Save (persists) an object to the database. This is where you would save the parent object [optionally, after updating an embedded object].
fn is a function that returns the object to be saved.
req, res as parameters.
hookFn is an optional function to do anything that might need to be done before saving. ie.
push()ing an embedded object into a parent object.
Specify a function callback to handle the final step after all the objects have been saved.
savedObj, req, res as parameters, where
savedObj is the object that was just saved.
fm.next(fn) will not be called if there was an error from the database. In the event of an error the middleware will call
Creates the middleware based on the configured
This middlware will render the provided view.
This middlware will validate the configured params.
This middleware will update the configured params on the given objects.
This middleware will persist the given objects to the database.
Returns an array of the
With npm do:
npm install express-mongodb-form-middleware