Dev Helpers

Node.js / POSIX paths

Join path segments

Dev Helpers · April 28, 2026

Joining path segments handles separators across supported platforms. Decide whether the result is intended for a local filesystem or a web URL.

Worked example

import { posix as path } from "node:path";
console.log(path.join("assets", "icons", "save.svg"));

Result

assets/icons/save.svg

Implementation notes

URL assembly and filesystem joining have different rules for separators and escaping. Keep helpers named for the kind of path they build.

Try it yourself

Join an empty segment and a segment that ends in a separator.

Open the Node.js example →

Editorial date April 28, 2026 · Published December 6, 2026

Related articles

Normalize dot segments

Normalizing dot segments simplifies the spelling of a path. It does not establish that the target exists or resolve symbolic links.

Read a file extension

The last extension alone cannot identify every compound file format. Treat extension parsing as a filename convention rather than content detection.

Resolve an absolute path

Resolving a relative path uses a base directory. A background job and a local shell may start from different working directories.