Matador

An Obvious MVC Framework for Node.js

About

Sane defaults and a simple structure, scaling as your application grows.

Matador is a clean, organized framework for Node.js architected to suit MVC enthusiasts. It gives you a well-defined development environment with flexible routing, easy controller mappings, and basic request filtering. It’s built on open source libraries such as Hogan.js for view rendering, Klass for its inheritance model, Valentine for functional development, and Express to give a bundle of other Node server related helpers.

Get the code on Github!

Installation

Get the CLI

$ npm install matador -g

Create an app

$ matador init app–name
$ cd !$ && npm install matador

Start the App

// server.js
require('matador').listen(3000)
$ node server.js && open http://localhost:3000

Dancing with the Bull

Routing

// app/config/routes.js
['get', '/hello/:name', 'Home', 'hello']
// app/controllers/HomeController.js
hello: function (name) {
  this.response.send('hello' + name)
}

View Rendering

// app/controllers/HomeController.js
this.render('index', {
  title: 'Bull Fighters'
})
<!-- app/views/layout.html -->
<!DOCTYPE html>
<html>
  <head>
    <title>{{title}}</title>
  </head>
  <body>
    {{{body}}}
  </body>
</html>
<!-- app/views/index.html -->
<h1>Welcome {{title}}</h1>

Model & Controller Class Interface

// app/controllers/UserController.js
module.exports = require('./ApplicationController').extend()
  .methods({
    show: function (id) {
      this.getModel('User').find(id, v.bind(this, function (user) {
        this.render('user', user)
      }))
    }
  })

Request Filtering

// app/controllers/ApplicationController.js
module.exports = require('./BaseController').extend(function () {
  this.addBeforeFilter(this.requireAuth)
  this.addExcludeFilter(['welcome'], this.requireAuth)
})
  .methods({
    requireAuth: function (callback) {
      if (this.request.cookies.authed) return callback(null)
      this.response.redirect('/welcome')
    }
  , welcome: function () {
      this.render('welcome')
    }
  })