Skip to content

Express.js #589

Answered by TatyOko28
Mercure28 asked this question in Q&A
Discussion options

You must be logged in to vote

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
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Mercure28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants