EN
Express.js - search parameters
0 points
In this article, we would like to show you how to get the search parameters in Express.js.
Search parameters are located in request.query
property.
So if we get GET request to example.com/example?id=1&username=xyz
, we can get the parameters via request.query.id
and request.query.username
.
Example with GET method:
xxxxxxxxxx
1
const express = require('express');
2
const app = express();
3
4
app.get('/user', (request, response) => {
5
const id = request.query.id;
6
// ... Here we can send a query to the database
7
8
response.send(foundUserData);
9
});
10
11
app.listen(3000);
When received GET request is /user?id=10
, then request.query.id
will be 10.