Skip to content
Justice Tech School

The path Module

path builds and parses file paths in a cross platform way. Never join paths with plain string concatenation.

Example
const path = require('node:path');
console.log(path.join('a', 'b', '../c', 'file.txt'));
console.log(path.basename('/x/y/report.pdf'), path.extname('report.pdf'));
console.log(path.parse('/home/ada/app.js').name);
console.log(path.isAbsolute('/tmp'));

Result

a/c/file.txt
report.pdf .pdf
app
true

Exercise

Get the file extension.

path.("a.js")

Quiz Test

Why use path.join?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.