Node.js Built-in Modules
๐ Covered in this chapter:
node:path ยท node:fs ยท node:os ยท node:url ยท node:events ยท node:crypto ยท node:stream
A tour of Node's core modules โ the batteries-included toolkit available without installing anything from npm.
1Node.js Built-in Modules โ What You'll Learn
A tour of Node's core modules โ the batteries-included toolkit available without installing anything from npm.
Here's everything this chapter covers, in the order you'll learn it:
- What built-in (core) modules are
- node:path โ file path utilities
- node:fs โ file system access
- node:os โ operating system information
- node:url โ URL parsing
- node:events โ the EventEmitter class
- node:util โ utility helpers
- node:crypto โ hashing and cryptography
- node:buffer โ binary data handling
- node:stream โ streaming data
- node:zlib โ compression
- node:readline โ reading input line by line
- node:child_process โ spawning external processes
- node:worker_threads โ CPU-bound parallel work
- node:test โ Node's built-in test runner
2Working Example
๐ป Example: Node.js Built-in Modules
JavaScript
โถ Run in Compiler
import os from "node:os";
import path from "node:path";
console.log("Platform:", os.platform());
console.log("CPU cores:", os.cpus().length);
console.log("Joined path:", path.join("src", "routes", "users.js"));
3Best Practices & Common Pitfalls
๐ก Key things to remember:
- Built-in modules are prefixed with node: (recommended) โ this avoids any ambiguity with npm packages of the same name.
- You never need to npm install these โ they ship with the Node.js runtime itself.
โ Frequently Asked Questions (FAQ)
Q What's the most important thing to understand about node.js built-in modules?
Focus on: node:path ยท node:fs ยท node:os ยท node:url ยท node:events ยท node:crypto ยท node:stream. These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.
Q Do I need external npm packages for node.js built-in modules?
Only where explicitly shown in the code examples above (like Express, Zod, or Socket.IO) โ otherwise, this chapter relies entirely on Node.js's own built-in capabilities.