Routing in Express: Routing in Express allows you to define how your application responds to client requests. It allows you to define a URL pattern and the corresponding function to execute when the pattern is matched. Here's an example of how to define a route in Express:
javascript
const express = require('express');
const app = express();
app.get('/users/:id', (req, res) => {
const userId = req.params.id;
res.send(`User ID: ${userId}`);
});
app.listen(3000, () => {
console.log('Server listening on port 3000');
});
No comments:
Post a Comment