{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/express/issues/2660","labels_url":"https://api.github.com/repos/strongloop/express/issues/2660/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/express/issues/2660/comments","events_url":"https://api.github.com/repos/strongloop/express/issues/2660/events","html_url":"https://github.com/strongloop/express/issues/2660","id":80225474,"number":2660,"title":"Unexpected behaviour from app.param middleware","user":{"login":"rudolfschmidt","id":1162911,"avatar_url":"https://avatars.githubusercontent.com/u/1162911?v=3","gravatar_id":"","url":"https://api.github.com/users/rudolfschmidt","html_url":"https://github.com/rudolfschmidt","followers_url":"https://api.github.com/users/rudolfschmidt/followers","following_url":"https://api.github.com/users/rudolfschmidt/following{/other_user}","gists_url":"https://api.github.com/users/rudolfschmidt/gists{/gist_id}","starred_url":"https://api.github.com/users/rudolfschmidt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudolfschmidt/subscriptions","organizations_url":"https://api.github.com/users/rudolfschmidt/orgs","repos_url":"https://api.github.com/users/rudolfschmidt/repos","events_url":"https://api.github.com/users/rudolfschmidt/events{/privacy}","received_events_url":"https://api.github.com/users/rudolfschmidt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/express/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/strongloop/express/labels/ideas","name":"ideas","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-24T17:59:09Z","updated_at":"2015-06-19T00:59:43Z","closed_at":"2015-06-19T00:59:43Z","body":"Hi,\r\n\r\napp.param shows an unexpected behaviour if it is used in another app instance.\r\n\r\n## Full and runnable JS code\r\n### app.js\r\n\r\n```javascript\r\n'use strict'\r\n\r\nvar express = require('express')\r\nvar app = express()\r\n\r\napp.use(require('./parameters'))\r\napp.use(require('./routes'))\r\n\r\napp.listen(5000)\r\n```\r\n\r\n### parameters.js\r\n\r\n```javascript\r\n'use strict'\r\n\r\nvar express = require('express')\r\nvar app = module.exports = express()\r\n\r\napp.param('user', function(req, res, next, id) {\r\n  console.log('param method called with id ', id)\r\n  req.user = {\r\n    id: id\r\n  }\r\n  next()\r\n})\r\n```\r\n\r\n### routes.js\r\n\r\n```javascript\r\n'use strict'\r\n\r\nvar express = require('express')\r\nvar app = module.exports = express()\r\n\r\napp.get('/:user', function(req, res) {\r\n  res.send(req.user.id)\r\n})\r\n```\r\n\r\n## Clear description of the problem or unexpected behavior.\r\n\r\nStarting the app with \r\n\r\n    node app.js\r\n\r\nand accessing \r\n\r\n    localhost:5000/test\r\n\r\nyou will get\r\n\r\n    TypeError: Cannot read property 'id' of undefined\r\n\r\nbecause app.param was never executed.\r\n\r\nInstead putting all together it works like here\r\n\r\n```javascript\r\n'use strict'\r\n\r\nvar express = require('express')\r\nvar app = module.exports = express()\r\n\r\napp.param('user', function(req, res, next, id) {\r\n  console.log('param method called with id ', id)\r\n  req.user = {\r\n    id: id\r\n  }\r\n  next()\r\n})\r\n\r\napp.get('/:user', function(req, res) {\r\n  res.send(req.user.id)\r\n})\r\n```\r\n\r\n## Clear description of the expected result.\r\n\r\nI would expect that the first code example should also work. So you can separate the code in differente files and mount them together.\r\n\r\n## Steps you have taken to debug it yourself.\r\n\r\nOnly the steps described here."},"comment":{"url":"https://api.github.com/repos/strongloop/express/issues/comments/113332461","html_url":"https://github.com/strongloop/express/issues/2660#issuecomment-113332461","issue_url":"https://api.github.com/repos/strongloop/express/issues/2660","id":113332461,"user":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"created_at":"2015-06-19T00:59:43Z","updated_at":"2015-06-19T00:59:43Z","body":"Closing due to lack of response and no PRs offered; if someone runs across this in the future, PRs are welcome :)"}}