Skip to content

Instantly share code, notes, and snippets.

@dominykas
Created August 1, 2013 13:10
Show Gist options
  • Save dominykas/6131160 to your computer and use it in GitHub Desktop.
Save dominykas/6131160 to your computer and use it in GitHub Desktop.
req.params get overwritten
For http://localhost:3000/1 the following output will be produced:
Matched /:id
[ id: '1' ]
Matched /*
[ '1' ]
Timeout in /:id
[ '1' ]
Notice how req.params inside the /:id handler has changed.
var app = require('express')();
app.get('/:id', function(req, res, next) {
console.log("Matched /:id");
console.log(req.params);
setTimeout(function () {
console.log("Timeout in /:id");
console.log(req.params);
}, 100);
next();
});
app.get('/*', function(req, res) {
console.log("Matched /*");
console.log(req.params);
res.send("OK");
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment