Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2011 23:14
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ded/1305237 to your computer and use it in GitHub Desktop.
Rails-like routes for Express
var express = require('express')
, app = express.createServer()
module.exports = {
index: function (req, res, next) {
res.render('index', {
title: 'Express'
module.exports.initialize = function (app) {
function match(method, route, controller, action) {
app[method](route, function (req, res, next) {
require('../controllers/' + controller)[action || 'index'](req, res, next)
match('get', '/', 'application', 'index')
Copy link

xonecas commented Oct 22, 2011

Is require async now? I remember that a few versions back it wasn't.

Copy link

ded commented Oct 22, 2011

they've always been sync as far as I know. With regards to this example, it definitely works, you should try it out on a default Express install

Copy link

skw commented Apr 11, 2013

express-coffee does something similar with express in CS, I'm kinda on the fence about using CS but it is a pleasure to work with...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment