1. path helpers
node:path provides cross-platform helpers for building and inspecting file paths.
import { join, resolve, basename } from "node:path";Typorithm · medium
Step 1 of 8 · intro card
File System & Streams
node:path builds cross-platform paths: join glues segments with the right separator, resolve makes an absolute path, basename extracts the file name. Buffer.from creates binary data and toString(encoding) serializes it, e.g. to base64.
node:path lets you build paths that work on any OS. join glues segments with the platform separator, resolve produces an absolute path, and basename pulls the final file name out of a path.
Hardcoding "/" or "\\" breaks across platforms; join and resolve pick the right separator for you, which is why they are the idiomatic way to construct paths.
Buffer represents raw binary data. Buffer.from("hi") wraps a string as bytes, and toString("base64") re-encodes those bytes — handy for transmitting binary as text.
join, resolve, basename build and inspect paths portably.
Avoid hardcoded separators — they break across platforms.
Buffer holds raw bytes; toString(encoding) serializes them.
import { join, resolve, basename } from "node:path";
const full = join(dir, "file.txt");
const encoded = Buffer.from("hi").toString("base64");Connect each part of the code to the concept before you type.
node:path provides cross-platform helpers for building and inspecting file paths.
import { join, resolve, basename } from "node:path";join concatenates segments with the correct separator for the current OS, avoiding hardcoded slashes.
join(dir, "file.txt")Buffer.from turns a string into a Buffer of raw bytes you can encode or write.
Buffer.from("hi")Calling toString with an encoding serializes the Buffer's bytes, here as base64.
.toString("base64")Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.