How to get GET (query string) variables in Express.js on Node.js?

Sometimes, we want to get GET (query string) variables in Express.js on Node.js.

In this article, we’ll look at how to get GET (query string) variables in Express.js on Node.js.

How to get GET (query string) variables in Express.js on Node.js?

To get GET (query string) variables in Express.js on Node.js, we can get the from the req.query property.

For instance, we write

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

app.get('/', (req, res) => {
  res.send('id', req.query.id);
});

app.listen(3000);

to get the id query string parameter value with req.query.id.

Conclusion

To get GET (query string) variables in Express.js on Node.js, we can get the from the req.query property.