Example - file.js

suggest change

In 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents