I'm learning how to use node.js and express following a guide, but can't seem to get part of it to work, even with identical code.
app.get('api/courses/:id', (req, res) =>
{
var courseCode = req.params.id;
console.log(`Received GET request for ${req.url}`);
//more code after this..
});
But none of the code ever runs - nothing is logged to the console when I use Insomnia to request /api/courses/54, or any other numbers and strings I've tried. My other code works, a GET request for /api/courses. But running this one just returns "Cannot GET /api/courses/54" and logs nothing.
Any help is appreciated
You should add the /
at the beginning of your path. So, it should be as follow:
app.get('/api/courses/:id', (req, res) => {
var courseCode = req.params.id;
console.log(`Received GET request for ${req.url}`);
//more code after this..
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments