Skip to content Skip to sidebar Skip to footer

Use Express.js To Get The Query String Of A Url

I'm looking for a way to get the query string part of a url using node.js or one of it's extension module. I've tried using url and express but they give me an array of parameters

Solution 1:

Use url.parse. By default it will return an object whose query property is the query string. (You can pass true as the second argument if you want query to be an object instead, but since you want a string the default is what you want.)

var url = require('url');

var urlToParse = 'http://www.mydom.com/?a=337&b=33';
var urlObj = url.parse(urlToParse);

console.log(urlObj.query);
// => a=337&b=33

Solution 2:

How about using the built-in url.parse method?


Post a Comment for "Use Express.js To Get The Query String Of A Url"