How to get an object with the query parameters of a URL in Node.js

3 Answers

0 votes
const url = require('url');
 
const testurl = new URL('https://www.website.com/orders/index.html?id=8372&age=43')
 
console.log(testurl.searchParams);
   
 
        
/*
run:
      
URLSearchParams { 'id' => '8372', 'age' => '43' }
    
*/

 



answered Mar 10, 2020 by avibootz
edited Mar 10, 2020 by avibootz
0 votes
const url = require('url');

const testurl = new URL('https://www.website.com/orders/index.html?id=8372&age=43')

const q = testurl.searchParams;

q.forEach(function(value, key) {
    console.log(key, value);
});
  

       
/*
run:
     
id 8372
age 43
   
*/

 



answered Mar 10, 2020 by avibootz
edited Mar 10, 2020 by avibootz
0 votes
const url = require('url');

const testurl = new URL('https://www.website.com/orders/index.html?id=8372&age=43')

const q = testurl.searchParams;

q.forEach((value, key) => {
    console.log(key, value);
});
  

       
/*
run:
     
id 8372
age 43
   
*/

 



answered Mar 10, 2020 by avibootz

Related questions

1 answer 247 views
1 answer 215 views
3 answers 373 views
1 answer 139 views
3 answers 250 views
1 answer 185 views
1 answer 126 views
...