Typorithm · medium

path & Buffer

path-buffernodejspathbuffercross-platform
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn path & Buffer

0%

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.

01

join, resolve, basename build and inspect paths portably.

02

Avoid hardcoded separators — they break across platforms.

03

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");

Read the implementation

Connect each part of the code to the concept before you type.

1. path helpers

node:path provides cross-platform helpers for building and inspecting file paths.

import { join, resolve, basename } from "node:path";

2. Join segments

join concatenates segments with the correct separator for the current OS, avoiding hardcoded slashes.

join(dir, "file.txt")

3. Make a Buffer

Buffer.from turns a string into a Buffer of raw bytes you can encode or write.

Buffer.from("hi")

4. Encode to base64

Calling toString with an encoding serializes the Buffer's bytes, here as base64.

.toString("base64")

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

path & Buffer: Lesson & Practice · Typorithm | ApplyDjinn