Skip to main content
D
Node.js
Node.js URL Module

Node.js URL Module

Node.js splits web addresses into readable parts.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

The Node.js URL module takes a long, messy web address and breaks it down into pieces. Developers use this to read specific search terms or understand exactly which page the user is trying to visit.

Example

Example
1/* this parses a URL */
2var url = require('url');
3var adr = 'http://localhost:8080/default.htm?year=2017&month=february';
4var q = url.parse(adr, true);
5
6console.log(q.pathname); // returns '/default.htm'
7console.log(q.query.year); // returns 2017

Key Points

  • Import the module using `require('url')`.
  • The `parse()` method splits the address.
  • It extracts the host, pathname, and query strings.
  • It returns an easy-to-read JavaScript object.

Up Next

Continue your journey with the next topic.

Go to Node NPM