Read files
Read configuration, templates, or other small files during asynchronous application work.
Node.js · Module
The node:fs module provides Node.js access to files and directories through synchronous, callback-based, and promise-based APIs. It is suited to reading, writing, opening, inspecting, and streaming filesystem data.
The node:fs module provides filesystem access through callback, synchronous, and promise-based APIs. Import the promise variant when asynchronous operations should be composed with await; common operations accept paths and optional encoding or options, while reads return data and writes complete after the file has been updated.
import * as fs from 'node:fs';
import * as fs from 'node:fs/promises';node:fs exposes filesystem operations modeled after POSIX behavior.node:fs/promises when you want promise-returning operations.node:fs for callback-oriented and synchronous filesystem APIs.import { readFile, writeFile } from 'node:fs/promises';
const input = await readFile('input.txt', 'utf8');
await writeFile('output.txt', input.toUpperCase());
console.log('Wrote output.txt');Reads a UTF-8 text file and writes an uppercase copy using promise-based filesystem APIs.
Read configuration, templates, or other small files during asynchronous application work.
Persist generated content, logs, or application state.
Process large files incrementally without loading them fully into memory.
Inspect paths, permissions, metadata, and directory contents.
node:fs/promisesfs.readFilefs.writeFilefs.openfs.accessfs.createReadStreamfs.createWriteStream