Express.js
#589
-
What is the difference between req.params, req.queryand req.bodyin Express.js? |
Beta Was this translation helpful? Give feedback.
Answered by
TatyOko28
Feb 8, 2025
Replies: 1 comment
-
req.params: Contains the URL parameters defined in the route app.get('/user/:id', (req, res) => {
console.log(req.params.id); // ID extrait de l'URL
}); req.query: Contains the parameters sent in the URL after the ? app.get('/search', (req, res) => {
console.log(req.query.q); // Recherche par mot-clé
}); req.body: Contains the data sent in the body of the request (POST/PUT). app.use(express.json());
app.post('/login', (req, res) => {
console.log(req.body.username); // Extraction du nom d’utilisateur
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Mercure28
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
req.params: Contains the URL parameters defined in the route
req.query: Contains the parameters sent in the URL after the ?
req.body: Contains the data sent in the body of the request (POST/PUT).