Simulator
Path Module Playground
Type any two paths and watch every path method recompute live. All results use POSIX rules — exactly what Node gives you on Linux and macOS.
Combining pathsuses A + B
path.join("/home/user/project", "src/index.js")"/home/user/project/src/index.js"join() simply glues segments together with '/' and normalizes the result. It never looks at the current working directory.
path.resolve("/home/user/project", "src/index.js")"/home/user/project/src/index.js"resolve() builds an absolute path, working right-to-left until it hits an absolute segment. If none is absolute it prepends the cwd (here: /home/user/project).
Dissecting a pathuses A
path.basename("/home/user/project")"project"The final segment — usually the file name.
path.dirname("/home/user/project")"/home/user"Everything before the final segment — the containing directory.
path.extname("/home/user/project")""From the last dot to the end. Dotfiles like .bashrc have no extension.
path.parse(A) — anatomy of a path
"/""/home/user""project""project"""Note that base = name + ext, and root is only "/" when the path is absolute.
path.format() — the inverse of parse()
path.format({"root":"/","dir":"/home/user","base":"project","name":"project","ext":""})"/home/user/project"format() rebuilds the string from a parsed object: dir + '/' + base. Round-tripping parse() → format() gives you back an equivalent path.
Why this matters: hand-concatenating paths with + breaks across platforms and mishandles .., duplicate slashes, and trailing separators. The path module handles all of that, and path.win32 / path.posix let you target a specific platform explicitly.