Standard library / path · on the one-page reference
path
Stable — pure string manipulation, no filesystem calls of its own. Newly added to Lumen, but resting on one of the oldest, least-churned corners of the runtime.
No filesystem access, just string logic. A practical subset of
Node's path
API — POSIX only (no path.win32), and
path.sep/path.delimiter are called as
path.sep()/path.delimiter() rather than read as
properties, since Lumen has no static-namespace constant mechanism yet.
path.basename(path, suffix?)
(string, string?) → string — the last path segment,
with suffix stripped if present.
console.log(path.basename("/foo/bar/baz.html")); // baz.html
console.log(path.basename("/foo/bar/baz.html", ".html")); // baz
path.dirname(path)
string → string — returns "." for a path
with no directory segment.
console.log(path.dirname("/foo/bar/baz.html")); // /foo/bar
path.extname(path)
string → string — "" for dotfiles like
.gitignore.
console.log(path.extname("index.html")); // .html
path.isAbsolute(path)
string → bool
console.log(path.isAbsolute("/foo/bar")); // true
path.normalize(path)
string → string — collapses ./..
segments; does not require the path to exist.
console.log(path.normalize("/foo/bar//baz/asdf/quux/..")); // /foo/bar/baz/asdf
path.join(...paths)
(string, string, ...) → string — 2 to 6 arguments;
joins then normalizes, matching Node's join definition.
console.log(path.join("/foo", "bar", "baz/asdf", "quux", "..")); // /foo/bar/baz/asdf
path.resolve(...paths)
(string, string, ...) → string — 1 to 6 arguments;
"cd"-chains left to right, an absolute segment resets the result. If no
argument is absolute, anchors to the real working directory to
guarantee an absolute result, matching Node. The only path.*
function that reads the real cwd — every other one stays pure
string manipulation.
console.log(path.resolve("/foo/bar", "./baz")); // /foo/bar/baz
console.log(path.resolve("foo", "bar")); // /foo/bar
path.parse(path)
string → { root, dir, base, name, ext } —
the second record-returning builtin after fs.statSync.
const p = path.parse("/home/user/dir/file.txt");
console.log(p.dir); // /home/user/dir
console.log(p.name); // file
path.format(parts)
{ root, dir, base, name, ext } → string
— the inverse of parse. Deviation from
Node: all five fields are required (Node allows omitting any of
them); round-tripping path.format(path.parse(p)) works
perfectly, building a literal by hand needs every field filled in.
console.log(path.format(path.parse("/home/user/dir/file.txt")));
// /home/user/dir/file.txt
path.sep()
→ string — always "/" (Lumen is POSIX-only).
Called as a function, not read as a property (see above).
console.log(path.sep()); // /
path.delimiter()
→ string — always ":".
console.log(path.delimiter()); // :