Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback


Deno standard library
Go to Latest
function dirname
import { dirname } from "";

Return the directory path of a URL. A directory path is the portion of a URL up to but excluding the final path segment. The final path segment, along with any query or hash values are removed. If there is no path segment then the URL origin is returned. Example, for the URL, the directory path is


Example 1

import { dirname } from "";

console.log(dirname("").href); // ""
console.log(dirname("").href); // ""


url: string | URL
  • url to extract the directory from.


a new URL containing the directory path of the URL.