Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics Middleware Middleware Sequence and Routing

Alexei Parphyonov
Alexei Parphyonov
34,128 Points

Don't get 'One and a half' printed to the console

Here is what I've got for the Middleware section (below App settings, above Routes).

app.use((req, res, next) => { console.log('One'); next(); }, (req, res, next) => { console.log('One and a half'); next(); }); app.use((req, res, next) => { console.log('Two'); next(); });

And I can't get 'One and a half' printed. Always get 'One Two One Two' in the console. Reduplication is thanks to redirecting I believe, but how do I get 'One and a half' anyways?

1 Answer

Tom Geraghty
Tom Geraghty
24,162 Points

I tried formatting your code and putting in a code block so I could find any errors. I don't see any. Can you copy in the rest of your server.js file so we can see if there's something else causing the problem?

Here is your code, pasted in from above, formatted:

app.use(
(req, res, next) => { 
  console.log('One'); 
  next(); 
}, 
(req, res, next) => { 
  console.log('One and a half'); 
  next(); 
}); 

app.use((req, res, next) => { 
  console.log('Two'); next(); 
});