kanso/node-couchapp — pull request #7 by jhs (2012-03-05 09:19:56+00:00)
Title: No more mock require()

This gets node-couchapp working, for me at least. I have no idea what backwards-compatibility it breaks, but it allows me to reach my goal if a super simple, slim, couch app.

This is my entire couch app:

var fs = require('fs')

var ddoc = module.exports = { 'views':{} }

fs.readdirSync(__dirname + '/views').forEach(function(file) {
var match = file.match(/^(.+)\.js$/)
, mod = match && match[1]

if(mod)
ddoc.views[mod] = require('./views/' + file)
})