Skip to content

Instantly share code, notes, and snippets.

@jincod
Created April 10, 2015 17:08
Show Gist options
  • Save jincod/16c7bec5d8c44431a142 to your computer and use it in GitHub Desktop.
Save jincod/16c7bec5d8c44431a142 to your computer and use it in GitHub Desktop.
express.js route builder from controllers
fs = require 'fs'
path = require 'path'
routes = fs.readdirSync('./server/controllers').map (f) ->
path.basename(f, path.extname(f))
addRouter = (app, name) ->
name = name.replace 'index', ''
app.use '/' + name, require './controllers/' + name
module.exports = (app) ->
for route in routes
addRouter app, route
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment