Example - file.js
suggest changeIn this example we have a file called file.js.
Suppose you need to parse a URL query string. Modern Node.js uses the web-standard URLSearchParams API:
To accomplish this all you have to do is to insert the following statement in your file:
const params = new URLSearchParams('foo=bar&abc=xyz&abc=123');
const result = {
foo: params.get('foo'),
abc: params.getAll('abc'),
};
console.log(JSON.stringify(result));
{"foo":"bar","abc":["xyz","123"]}
get() returns the first value for a key, while getAll() returns every repeated value. The same API is available in current browsers.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents