Bauer", gender: 'female'}, {name: "Jack Smith", gender: 'male'}]; function validate(req, res, next, id) { if(id >= 0 && id < data.length) { next(); } else { res.json({}); res.end(); } } var express = require('express'); var app = express(); app.set('views', './views') app.set('view engine', 'jade') app.param('id', validate); app.get("/employees\/:id([0-9]+?)$", function(req, res) { res.render('data', data[req.params.id]); }); app.post("/employees\/:id([0-9]+?)$", function(req, res) { res.json(data[req.params.id]); }); var server = app.listen(3000, function () { console.log('Server listening'); }); }())