git clone https://gist.github.com/a5656b01c35d6f25dda7.git democd demonpm installnpm start
Look at the purty code. See how the magic be done.
| # app.coffee | |
| 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.type('.txt') | |
| 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. | |
| try | |
| process.setgid('nogroup') | |
| process.setuid('nobody') | |
| console.log "Server running on port #{port}".green | |
| console.log "Try visiting http://localhost/test/user/homework/stuff?key=value" |
| { | |
| "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 app.coffee when you run `npm start`. | |
| process.chdir(__dirname); // For safer use relative paths | |
| require('coffee-script/register'); // Use CoffeeScript | |
| require('./app'); // Actual server code |