Languages
[Edit]
EN

Node.js / Express.js - search parameters

0 points
Created by:
nickkk0
467

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:

const express = require('express');
const app = express();

app.get('/user', (request, response) => {
    const id = request.query.id;
    // ... Here we can send a query to the database

    response.send(foundUserData);
});

app.listen(3000);

When received GET request is /user?id=10, then request.query.id will be 10

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join