Programming/Javascript / / 2021. 11. 19. 17:26

url, query string 모듈

728x90
const url = require("url");
const querystring = require("querystring");
const parsed = url.parse("https://nyaongnyaong.com/40?category=833145");

console.log(parsed);
console.log(querystring.parse(parsed.query));

console.log(parsed); =>

{
    protocol: 'https:',
    slashes: true,
    auth: null,
    host: 'nyaongnyaong.com',
    port: null,
    hostname: 'nyaongnyaong.com',
    hash: null,
    search: '?category=833145',
    query: 'category=833145',
    pathname: '/40',
    path: '/40?category=833145',
    href: 'https://nyaongnyaong.com/40?category=833145'
}

 

console.log(querystring.parse(parsed.query)); =>

{

    category: '833145'

}

 

참고로 query string 모듈은 있다는 걸 쓴 것이고 url 모듈로 충분합니다.

반응형