node:fs
The built-in Node.js module for working with files and folders, in promise, callback and synchronous forms.
In more detail
The promise API in node:fs/promises is the modern choice: every function returns a promise and the work runs on libuv's thread pool. The Sync functions block the event loop and suit scripts and start-up code.
Example
Next.js Server Components in the Node.js runtime can read files with it; the Edge runtime cannot.Related terms
- Node.js built-in modules — Modules that come with Node.js itself, such as fs, path, crypto and child_process.
- Node.js runtime — The default Next.js runtime, where server code runs on Node.js with access to every Node API and npm package.
- FileHandle — The object fs/promises open() returns for an open file, wrapping its file descriptor with promise-based read, write and close methods.
- fs.readFile() — Convenience functions that read a whole file into memory, or write a whole file, in one call.
- fs.readdir() — The Node.js function that lists the entries of a directory, optionally with their types and optionally including every subdirectory.
- thread pool — A fixed or bounded set of reusable worker threads that take tasks from a queue, instead of creating a new thread for each task.
Taught in
- Runtime Environments: Node.js vs Edge Runtime Choice — Next.js 15 & Modern App Router Architecture
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services
- Asynchronous File I/O: node:fs/promises & Handles — Node.js Internals & Backend Services
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services