mcl

0.0.2 • Public • Published

mcl

A simple script to help load models and controllers dynamically

Install:

npm install

After install, run

cd node_modules/mcl
node postinstall.js

To automatically set up folders and template files

Examples

Example routes.json

{
  "/route": {
    "http-method":"controller-name.method"
  },
  "/": {
    "get":"index.view",
    "post":"index.add"
  }
}

Example model

module.exports = {
  schema: {
    createdAt: {
      type: Date,
      required: true,
      index: true
    },
    user: {
      type: String,
      required: true,
      index: true
    },
    title: {
      type: String,
      required: true
    },
    body: {
      type: String,
      required: true
    }
  },
  methods: {},
  statics: {}
}

Usage

Example:

app.set('models', __dirname +'/models')
app.set('controllers', __dirname +'/controllers')
app.set('routes', __dirname +'/routes.json')
var mvc = require('mvc')(app)
app.models = mvc.loadModels(fs, db)
mvc.loadRoutes(mvc.loadControllers(fs))

db should be a mongoose db connection instance as in mongoose.connect()

To use a model;

app.models.modelFileName.method()

Readme

Keywords

none

Package Sidebar

Install

npm i mcl

Weekly Downloads

1

Version

0.0.2

License

none

Last publish

Collaborators

  • ptte