fs (File System)

The fs module enables you to interact with the file system.

It provides both synchronous and asynchronous methods for performing common file operations such as reading, writing, updating, deleting, and watching files and directories.

ESM
import fs from 'fs'

Sync and asynchronous

The fs module supports three main styles of usage - synchronous, asynchronous, and Promise-based. Synchronous usage is simpler, but blocks execution until the operation completes.

Loading TypeScript...

Reading files

The function fs.readFileSync reads a file synchronously, meaning the Node.js process waits for the operation to complete before doing anything else.

Loading TypeScript...

Was this page helpful?