Reputation: 15081
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. I want to original string. Any ideas ?
example; for:
give me
a=337&b=33
(with or without the ?)
Upvotes: 0
Views: 276
Reputation: 106147
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
Upvotes: 4