Can we get the variables in the query string in Node.js just like we get them in $_GET
in PHP?
I know that in Node.js we can get the URL in the request. Is there a method to get the query string parameters?
To parse query string in Node. js, we can use the url module. const http = require('http'); const url = require('url'); const server = http. createServer((request, response) => { const { query: queryData } = url.
Since you've mentioned Express.js in your tags, here is an Express-specific answer: use req.query. E.g.
var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('id: ' + req.query.id); }); app.listen(3000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With