Skip to content
Guest
Learn Node.js · Course Syllabus Show lessons
Backend APIs · 8 min read · Intermediate

Streams, Buffers & Crypto Hashing

Process large payloads with constant memory using Node streams and generate secure hashes with node:crypto.

What you'll learn

  • Understand why streams handle gigabyte files without exhausting RAM
  • Generate cryptographically secure tokens with crypto.randomBytes()
  • Hash payloads cleanly with crypto.createHash('sha256')

Reading a 2 GB log file with fs.readFile() loads all 2 GB into RAM at once. Streams process chunks (typically 64 KB at a time) using constant memory. Meanwhile, node:crypto gives you built-in SHA-256 hashing, HMAC signatures, and secure random token generation (crypto.randomUUID()).

Fill-in-the-Blank Exercise

SHA-256 Digest with node:crypto

Compute the hex SHA-256 hash of a string.

const crypto = require("node:crypto");
const hash = crypto.createHash("").update("devpath").digest("");

Live Code Lab (Node.js 20)

Node.jscrypto_demo.js
Expected OutputClick “Run Live” to compile with Node.js 20
SHA-256 prefix: 0e635254d02df3d0
Secure token hex length: 32

Check Your Understanding

Score: 0 / 1

1. Why should you use streams instead of fs.readFile() when serving large video or CSV files?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind