Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Express Parameter Parsing Demo
colors = require 'colors'
express = require 'express'
bodyParser = require 'body-parser'
port = 8080
app = express()
app.use bodyParser.urlencoded
extended: true
app.get '/test/:user/:homework/:stuff', (req, res) ->
res.send """User: #{req.params.user}
Hw: #{req.params.homework}
Stuff: #{req.params.stuff}
Query: #{JSON.stringify(req.query)}"""
app.listen port
# If we were started by root drop permissions.
console.log "Server running on port #{port}".green
console.log "Try visiting http://localhost/test/user/homework/stuff?key=value"

Simple Express Parameter Parsing Demo

  1. git clone demo
  2. cd demo
  3. npm install
  4. npm start

Look at the purty code. See how the magic be done.

"name": "parse_demo_for_express",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"author": "Will Hilton",
"license": "MIT",
"dependencies": {
"body-parser": "^1.9.2",
"coffee-script": "^1.8.0",
"colors": "^1.0.3",
"express": "^4.10.1"
// server.js
// This is a bootstrap file to run when you run `npm start`.
process.chdir(__dirname); // For safer use relative paths
require('coffee-script/register'); // Use CoffeeScript
require('./app'); // Actual server code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment