Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why is my second middleware not running at all?

Not sure what I'm doing wrong but i keep getting the error message below after running localhost:3000/different/33 or any number to test the different/:id route.

'use strict';

const express = require('express'); const app = express();

//app.use for the middleware app.use('/', (res,req,next) => { console.log('First Middleware') next(); })

app.use('/different/:id', (res,req,next) => { console.log("Second Middleware ID:", req.params.id) next(); })

const port = process.env.PORT || 3000;

app.listen(port, () => { console.log('running on', port); })

TypeError: Cannot read property 'id' of undefined at app.use (C:\Users\demar\Desktop\july2018\basic-rest-api\app.js:14:54) at Layer.handle [as handle_request] (C:\Users\demar\Desktop\july2018\basic-r est-api\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (C:\Users\demar\Desktop\july2018\basic-rest-api\node_modules\ express\lib\router\index.js:317:13) at C:\Users\demar\Desktop\july2018\basic-rest-api\node_modules\express\lib\r outer\index.js:284:7 at param (C:\Users\demar\Desktop\july2018\basic-rest-api\node_modules\expres s\lib\router\index.js:354:14) at param (C:\Users\demar\Desktop\july2018\basic-rest-api\node_modules\expres s\lib\router\index.js:365:14) at Function.process_params (C:\Users\demar\Desktop\july2018\basic-rest-api\n ode_modules\express\lib\router\index.js:410:3) at next (C:\Users\demar\Desktop\july2018\basic-rest-api\node_modules\express \lib\router\index.js:275:10) at C:\Users\demar\Desktop\july2018\basic-rest-api\app.js:9:5 at Layer.handle [as handle_request] (C:\Users\demar\Desktop\july2018\basic-r est-api\node_modules\express\lib\router\layer.js:95:5)