📂
File System25M+/wkMIT

fs-extra

fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system methods not included in the standard library. The package pr

Installation

npm
npm install fs-extra
yarn
yarn add fs-extra
pnpm
pnpm add fs-extra

Import

ESM
import fse from 'fs-extra';

Quick Example

usage
import fse from 'fs-extra';

await fse.copy('src', 'dist');
await fse.ensureDir('logs/2024');
await fse.writeJson('config.json', { port: 3000 }, { spaces: 2 });
const config = await fse.readJson('config.json');
await fse.remove('tmp');

About fs-extra

fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system methods not included in the standard library. The package provides all methods from fs (and fs/promises) plus commonly needed operations like copy (recursive directory copying), move (cross-device file moving), mkdirs/ensureDir (recursive directory creation), remove (recursive deletion like rm -rf), ensureFile (create file and parent directories), readJson/writeJson (JSON file I/O with formatting), outputFile (write file creating parent directories), and emptyDir (remove directory contents without removing the directory). Every method supports both callback and promise-based APIs, and provides synchronous variants. fs-extra handles edge cases that raw fs operations miss — copy handles symlinks, permissions, and timestamps; move works across filesystem boundaries; and mkdirs handles race conditions in concurrent directory creation. The package is one of the most depended-upon in the npm ecosystem because it eliminates the need to compose multiple fs calls with error handling for common file operations. fs-extra is essential for build scripts, CLI tools, file processing pipelines, and any Node.js application that performs non-trivial file system operations.

Quick Facts

Packagefs-extra
CategoryFile System
Weekly Downloads25M+
LicenseMIT
Installnpm install fs-extra

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.