Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The url module from node

branch: master

add license

latest commit 258407d4a0
Isaac Z. Schlueter authored January 25, 2011
Octocat-spinner-32 LICENSE add license January 25, 2011
Octocat-spinner-32 Copy node url doc to readme January 25, 2011
Octocat-spinner-32 package.json add license January 25, 2011
Octocat-spinner-32 test-url.js url package January 25, 2011
Octocat-spinner-32 url.js url package January 25, 2011


This module has utilities for URL resolution and parsing. Call require('url') to use it.

Parsed URL objects have some or all of the following fields, depending on whether or not they exist in the URL string. Any parts that are not in the URL string will not be in the parsed object. Examples are shown for the URL


  • href: The full URL that was originally parsed.

    Example: ''

  • protocol: The request protocol.

    Example: 'http:'

  • host: The full host portion of the URL, including port and authentication information.

    Example: ''

  • auth: The authentication information portion of a URL.

    Example: 'user:pass'

  • hostname: Just the hostname portion of the host.

    Example: ''

  • port: The port number portion of the host.

    Example: '8080'

  • pathname: The path section of the URL, that comes after the host and before the query, including the initial slash if present.

    Example: '/p/a/t/h'

  • search: The 'query string' portion of the URL, including the leading question mark.

    Example: '?query=string'

  • query: Either the 'params' portion of the query string, or a querystring-parsed object.

    Example: 'query=string' or {'query':'string'}

  • hash: The 'fragment' portion of the URL including the pound-sign.

    Example: '#hash'

The following methods are provided by the URL module:

url.parse(urlStr, parseQueryString=false)

Take a URL string, and return an object. Pass true as the second argument to also parse the query string using the querystring module.


Take a parsed URL object, and return a formatted URL string.

url.resolve(from, to)

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

Something went wrong with that request. Please try again.