Skip to content

query-string

6,810 2 27 MIT
9.1.1 (9 Oct 2024) Nov 13 2013 54.8 million (month)

The query-string library is a Node.js library that provides a simple way to parse and stringify query strings. It is useful for working with the query string portion of a URL, which is the part of the URL that follows 'the "?" character and contains key-value pairs.

Example Use


import queryString from 'query-string';

console.log(location.search);
//=> '?foo=bar'

const parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}

console.log(location.hash);
//=> '#token=bada55cafe'

const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}

parsed.foo = 'unicorn';
parsed.ilike = 'pizza';

const stringified = queryString.stringify(parsed);
//=> 'foo=unicorn&ilike=pizza'

location.search = stringified;
// note that `location.search` automatically prepends a question mark
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'

Alternatives / Similar


585 10.0.1 (10 months ago) May 05 2015 compare
ip
1,520 2.0.1 (1 year, 6 months ago) Aug 15 2012 compare
6,256 0.1.3 (3 years ago) Jun 18 2013 compare

Other Languages

1,229 0.6.4 (10 months ago) Dec 28 2012 compare
1,369 1.2.1 (1 year, 2 months ago) Feb 14 2011 compare
url
103 v2.1.3 (9 months ago) Apr 15 2018 compare
Was this page helpful?