Node.js URL Handling

The URL module in Node.js is used to work with and analyze URLs.

Example

const { URL } = require("url");

const myURL = new URL(
    "https://example.com/products?id=101"
);

console.log("Host:", myURL.host);
console.log("Path:", myURL.pathname);
console.log("Query:", myURL.search);
        
Example Output:

Host: example.com
Path: /products
Query: ?id=101

Common URL Properties

← Back to Home