swag-mvc
connecting your models and routes in node.js
Creating
var mvc = require('mvc')( app )
Pass inexpress.createServer()
Models
mvc.initModels( models, dir, setupFunction, args )
sets up models indir
defined in the array of stringsmodels
.setupFunction
has two arguments, one is the capitalized name of the model and the other is the return value of the model file indir/ModelName
to hook it into your database of choice.args
are arguments passed into the model file.
Routes
mvc.initRoutes( routes, dir, args )
sets up the routes indir
, defined with an array of stringsroutes
, passing inapp
, corresponding model if applicable, followed by additionalargs
.
Example
app.js
mvc = app ; db = mongoose; mvc; mvc;
ROOT/controllers/users.js
// Passing in arguments app, the model, and arguments object passed in // during initRoutes module { app
ROOT/models/User.js
module { mongoose = argsmongoose; ObjectId = mongooseSchemaTypesObjectId; UserSchema = {}; // this is the schema passed into the // setupFunction in initModels return UserSchema; };
Testing
Run node tests/runTests.js
from project root -- testing uses nodeunit