The basename is the last named part of a path. Removing an extension is a separate operation with case-sensitive edge cases.
Worked example
import { posix as path } from "node:path";
console.log(path.basename("/tmp/report.csv"));Result
report.csvImplementation notes
A user-facing filename might contain several suffixes. Decide whether the display should preserve the complete name or remove a recognized extension.
Try it yourself
Compare a trailing separator, a dotfile and an uppercase extension.
Open the Node.js example →Editorial date August 21, 2025 · Published December 6, 2026