Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *