URL Parse NodeJS Deprecated

Viewed 1368

How to transform this below deprecated URL parse on Node v14 and express v4. I tried few changes but still failed.

url = require('url');
var url_parts = url.parse(req.url, true);
var query = url_parts.query; 
base_grant_url = query.base_grant_url;

The code originally from github rafael-carvalho/meraki-azure-ad

1 Answers

Express gives access to the query part of the request through req.query. It's not entirely clear what you are hoping to accomplish, but if you want to parse the following url:

hostname.com/path?base_grant_url=urlValue

The following will be true in your request handler:

req.query.base_grant_url === "urlValue"

And so instead of the code

url = require('url');
var url_parts = url.parse(req.url, true);
var query = url_parts.query; 
base_grant_url = query.base_grant_url;

You could just write

base_grant_url = req.query.base_grant_url
Related