node:path API Reference

POSIX and Windows path manipulation

import path from "node:path";

console.log(path.join("src", "app", "index.js"));
console.log(path.parse("archive.tar.gz"));
console.log(path.matchesGlob("src/a/b.js", "src/**/*.js")); // true

The standard methods are available: basename, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, toNamespacedPath, and matchesGlob.

path.posix and path.win32 expose explicit flavors on every host. The default export follows the current host. Their separators are available as sep and path-list delimiters as delimiter.

matchesGlob supports wildcards, globstar, character classes, brace alternation, and extglob patterns. A leading-dot basename such as .bashrc has an empty extension, and the final dot determines a multi-part extension.

path.parse(".bashrc").ext; // ""
path.parse("archive.tar.gz").ext; // ".gz"
path.win32.normalize("C:\\temp\\foo\\..\\"); // "C:\\temp\\"

See the Node.js path documentation for the standard edge cases and argument validation.