node package manager

mock-middleware

mock-middleware

express middleware for mocking and debugging

features

  • support code hot replacement
  • detect routes automatically

usage

  1. install middleware

    var app  = new express()
    ...
    var middleware = require('mock-middleware')
    app.use('/api', middleware(module, './routesDirectory'))
    ...
  2. write routes in routesDirectory to produce mock data

    module.exports = function(router){
      router.get(/\/test$/, function(req, res){
        // https://github.com/nuysoft/Mock/
        var Mock = require('mockjs')
        res.json(Mock.mock({ ... }))
      })
    }