A mistake:
In content:
app.use('/sorcerer', (req, res, next) => {
console.log('User has hit endpoint /sorcerer');
next();
});
this middleware function will not execute if the user hits a different path (for instance: '/spells'
or '/sorcerer/:sorcerer_id'
).
Correct one:
From Express document:
A route will match any path that follows its path immediately with a “/
”. For example: app.use('/apple', ...)
will match “/apple”, “/apple/images”, “/apple/images/news”, and so on.
For example:
This will match paths starting with /abcd
:
app.use('/abcd', function (req, res, next) {
next()
})
It’s been two and a half years since your comment, and everything you said here is still true. I’m going to have to look elsewhere to actually learn express.js. It really doesn’t seem that tricky when I look it up elsewhere but Codecademy manages to make it feel impossible to learn.
1 Like
Hello Codecademy,
I hope this message finds you well. While reviewing some code related to our web development curriculum, I encountered a specific usage that has piqued my curiosity. In the code, there is an app.use('/beans/:beanName')
followed by subsequent changes applied to app.post('/beans/:beanName/add')
.
I am eager to gain a deeper understanding of how '/beans/:beanName/add'
matches '/beans/:beanName'
in this context. Is this a result of a Single Path middleware, or does it transform into a Global middleware? I would greatly appreciate it if you could shed light on the underlying concept or mechanism responsible for this matching behavior.
Thank you for your time and assistance.
Sincerely, Mohamed Ouanjine
Just bumping this comment because it’s been three and half years since your comment, and everything you said here is still true. Probably going to put express.js on the back burner for now and have to revisit on a different platform. It’s extremely frustrating as someone who’s just learning because you feel like you’re doing something wrong and it’s very demotivating!
Two years later and I’m thinking the same thing!
Complaining about course content here will amount to nothing; it’s a black hole. No one from CC checks here.
If you find a bug or issue with the course content, you can always report them within the lesson itself under “Get Unstuck”.
Or, you can submit a request to the CC help desk/CS here, via the Get Help>Fix a Problem>Contact CS:
https://help.codecademy.com/hc/en-us/requests/new
1 Like