I'm new to Node.js and Express and I'm wondering the if the following code is correct:
router.get('students/:name', async (req, res) => {
const students = await Student.find(req.params.name);
res.send(students);
});
router.get('students/:age', async (req, res) => {
const students = await Student.find(req.params.age);
res.send(students);
});
So how can Express figure out which route to use one passing only one parameter? For example, when I call localhost:3000/students/20
, what if some students are 20 years old and some students have the name of "20"?