Dev Helpers

JavaScript / Node and testing

Build an OS-independent path

Dev Helpers · November 30, 2026

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Worked example

import path from "node:path";
console.log(path.join("reports", "2026", "summary.json"));

Result

reports/2026/summary.json

Implementation notes

A browser asset path always uses URL syntax. An OS-native separator introduced during a build can create a URL that appears correct on one machine only.

Try it yourself

Compare a filesystem path for Windows with a slash-separated URL path.

Open the JavaScript example →

Editorial date November 30, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.

Get the last day of a month

Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.