Mongoose logic on the client for web applications using modul8
m8-mongoose is a modul8 plugin that aims to partially port mongoose logic to the client.
A web application using mongodb on its backend and using mongoose as an ORM layer ends up defining a lot of validation logic on the server. Logic that should be reused on the client. This plugin will export sanitized versions of your explicitly exported mongoose models, along with helpers to utilize this data in a helpful way.
Willingness to perform an extra function call when defining your mongoose modules.
$ npm install m8-mongoose
then require the register function, and register a model with it
var Schema = Schema;var toBrowser = register;User =;
The output Schema instance is mongoose compatible (toBrowser remembers the extra attributes like
private, but returns an object without these).
On deployment, the plugin will pass back the serialized version of what was passed in above to modul8
var modul8 =var MongoosePlugin = Plugin;;
An optional first parameter to the MongoosePlugin constructor can be set, which will specify the name of the domain and data key used when exporting. This parameter defaults to 'mongoose'.
register() serializes the model to the plugins 'runtime' directory, whereas
MongoosePlugin will read these for modul8.
Code to help auto generate certain form code and validation logic is (soon) included on the
mongoose domain, and will be bundled with the output source if required
by the application.
You can extend the classical mongoose object with certain unused attributes. These work as follows:
private- if true, it this key will not be sent to the client
label- if set, it will be used by formGenerator to construct standard text inputs
labels- if set to array, it will be used by formGenerator to construct a select input
These attributes will be removed before passing the object back to mongoose's Schema constructor.
MIT Licensed - See LICENSE file for details