Dev Helpers

Node.js / POSIX paths

Read a file extension

Dev Helpers · December 24, 2025

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

Worked example

import { posix as path } from "node:path";
console.log(path.extname(".env.local"));

Result

.local

Implementation notes

An extension check is useful for choosing a processing path, but the parser must still validate the actual file contents.

Try it yourself

Compare an archive ending in .tar.gz, a hidden file and a directory name.

Open the Node.js example →

Editorial date December 24, 2025 · Published December 6, 2026

Related articles

Join path segments

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

Normalize dot segments

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

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.