Languages
[Edit]
EN

Express.js - search parameters

0 points
Created by:
nickkk0
647

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

Alternative titles

  1. Express.js - request parameters
  2. Express.js - query variables
  3. Express.js - query parameters
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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