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 trialOliver Statt
5,175 PointsWhy no params when calling mid.loggedOut ?
When we call the mid.loggedOut(req, res, next) function in our route, why is it that we dont need to pass the parameters, like:
router.get('/login', mid.loggedOut(req, res, next), (req, res) => { // route });
1 Answer
miikis
44,957 PointsHi Oliver,
There are no parameters because mid.loggedOut is not being called. If you look closely, you'll see that there are no parentheses after mid.loggedOut. All that's happening is that we're passing the function itself as a parameter, as a middleware. Express — the framework — is the one that ends up calling mid.loggedOut and as it calls it, it'll be the one that provides req, res, next parameters. Let me know if that didn't make sense.
Oliver Statt
5,175 PointsOliver Statt
5,175 PointsYes that makes sense :) Thank you for your answer.