runtime:path

Modern, platform-aware path utilities. Pure computation — no I/O. The host platform and working directory come from runtime:process, so separators and resolve() follow the real OS.

Capability: Env

Exposed as an ES module under the runtime: scheme. Status: Available.

One platform-correct surface — no posix/win32 dual namespaces and no overloaded signatures — plus first-class file: URL interop: dirname(fromFileURL(import.meta.url)) is the modern __dirname.

Import

JavaScript
import { join, resolve, dirname, fromFileURL } from "runtime:path";

// The modern __dirname: the directory of the current module.
const here = dirname(fromFileURL(import.meta.url));
const cfg = resolve(here, "config", "app.json");

Exports

ExportTypeDescriptionExample
sepstringPath segment separator for the host OS ("/" or "\").sep; // "/" on POSIX
delimiterstringPath list delimiter for the host OS (":" or ";").env.PATH.split(delimiter)
isAbsolute(p)(string) => booleanWhether p is an absolute path.isAbsolute("/etc/hosts") // true
normalize(p)(string) => stringCollapses . / .. and redundant separators.normalize("/a/./b/../c") // "/a/c"
join(...segments)(...string) => stringJoins segments with the separator, then normalizes.join("src", "lib", "x.js") // "src/lib/x.js"
resolve(...segments)(...string) => stringResolves to an absolute path, anchoring at cwd() if no segment is absolute.resolve("data", "out.json")
dirname(p)(string) => stringThe directory portion of p.dirname("/var/log/app.log") // "/var/log"
basename(p)(string) => stringThe final segment of p (no suffix-stripping overload).basename("/var/log/app.log") // "app.log"
extname(p)(string) => stringThe extension of the final segment, including the dot (or empty).extname("archive.tar.gz") // ".gz"
parse(p)(string) => object{ root, dir, base, name, ext }.parse("/a/b.txt")
relative(from, to)(string, string) => stringRelative path from from to to (both resolved first).relative("/a/b", "/a/c/d") // "../c/d"
fromFileURL(url)(string | URL) => stringConverts a file: URL to a path.fromFileURL(import.meta.url)
toFileURL(p)(string) => URLConverts a path (resolved to absolute) to a file: URL.toFileURL("/a/b.txt").href // "file:///a/b.txt"

Errors

ErrorWhen
TypeErrorA path segment isn't a string, or fileURLToPath() gets a non-file: URL. (Pure string functions — no capability, no I/O.)
Last updated on
Edit this page