Resolving a relative path uses a base directory. A background job and a local shell may start from different working directories.
Worked example
import { posix as path } from "node:path";
console.log(path.resolve("/srv", "../etc", "demo"));Result
/etc/demoImplementation notes
A current-working-directory dependency can make tests pass locally and fail in a job runner. Pass an explicit base for application-owned files.
Try it yourself
Run the calculation from two different working directories.
Open the Node.js example →Editorial date October 19, 2025 · Published December 6, 2026