path.normalize()

Normalizes a path, resolving `..` and `.` segments and redundant separators.

Since Node 0.x Spec ↗

Syntax

path.normalize(path)

Parameters

NameTypeRequiredDescription
path string Yes The path to normalize.

Returns

string — The normalized path string.

Examples

import { normalize } from 'node:path';

console.log(normalize('/foo/bar//baz/../qux'));
Output
/foo/bar/qux
import { normalize } from 'node:path';

console.log(normalize('a/b/./c/'));
Output
a/b/c/

Notes

Does not touch the filesystem and does not make a path absolute. Trailing separators are preserved. Normalizing untrusted input does not prevent path traversal on its own; also validate the result is within an allowed base directory.

See also