node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Browser Mongoose via 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.



  • mongodb
  • mongoose
  • modul8

Willingness to perform an extra function call when defining your mongoose modules.


Install with

$ npm install m8-mongoose

then require the register function, and register a model with it

var Schema = require('mongoose').Schema;
var toBrowser = require('m8-mongoose').register;
User = new Schema(toBrowser('user', {
  name : String
  pass : {type: String, private: true}

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 = require('modul8')
var MongoosePlugin = require('m8-mongoose').Plugin;
  .use(new MongoosePlugin())

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'.


Calls to 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