Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Last active December 20, 2015 19:09
Show Gist options
  • Save davidchambers/6180729 to your computer and use it in GitHub Desktop.
Save davidchambers/6180729 to your computer and use it in GitHub Desktop.
Express routing using regular expressions with named capturing groups
express = require 'express'
app = express()
app.param (name, arg) -> switch Object::toString.call arg
when '[object RegExp]'
(req, res, next, val) ->
if arg.test val then next() else next 'route'
app.param 'id', /^\d+$/
app.get '/things/:id', (req, res) -> res.send req.params.id
app.listen 8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment