Express.js - Route Parameters
Route Parameters is used to retrieve the values from the URl and make them available to your route handlers.
Route Parameters in Express.js
index.js
const express = require('express'); const app = express(); // Route with a dynamic parameter (:name) app.get('/user/:name', (req, res) => { // Extract the name parameter from the request const name = req.params.name; // Response with a message res.send(`Hello, ${name}`); }); const PORT = 5000; app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });
Run the Server
Run the server using the command given below.
node index.js
D:\my-app>node index.js Server is running on http://localhost:5000