mongoose-helper
v0.0.2
Published
A helper to bring more granular structure to your Mongoose models.
Downloads
3
Readme
Mongoose Helper
Mongoose Helper is a utility that imposes a granular organisation structure for your Mongoose models and aids in following our style guide for Node.js applications for the following mongoose features:
- Schema
- Methods
- Statics
- Virtuals
- Middleware (Post/Pre Saving)
- Validation
Todo
- Link to Node.js applicaton style guide
- Middleware (Post/Pre Saving)
- Validation
- Contributing guidelines
- License
Requirements
You will need to install Mongoose for your application. We do not require any version of Mongoose in this packages dependencies to give you the flexibility to use your own version of Mongoose.
Overview
Mongoose Helper encourages the use of feature folders for organising your application, following the principles of Node.js API Style Guide
Each piece of functionality should live it its own file. E.g. Each method/static will reside in independant files under the methods/statics folder respectively. Here's a sample folder structure.
lib/
users/
controller/
model/
schema.js
methods/
reset-password.js
update-password.js
statics/
signup.js
find-or-create.js
posts/
contoller/
model/
...
Structuring your models (and any module) like this aids in testing, maintaining and reusing your Mongoose models.
When you create your model with Mongoose Helper, your model will be automatically loaded and instantiated based on your directory structure.
See the test/fixtures folder of the repository for an example of how to use Mongoose Helper.