I'm currently facing an issue with a small program I'm developing to practice Express.js.
The problem lies in a separate router that is supposed to send a specific response based on the route. For example, when navigating to "/santiago", it should display "Hi Santiago", but instead, it shows "Hi undefined". This is the code for the router named name.js:
//name.js
const express = require('express');
const router = express.Router();
router.get('/', (req,res) => {
res.send("Hi " + req.params.name);
});
module.exports = router;
And here's the code for app.js:
//app.js
const express = require('express');
const app = express();
let port = process.env.PORT || 3000;
app.listen(port);
const name = require('./name');
app.use('/:name', name);
app.get('/', (req,res) => {
res.send("Welcome");
});
Can you spot the mistake?