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 install fs-extra
yarn add fs-extra
pnpm add fs-extra
Import
import fse from 'fs-extra';
Quick Example
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
| Package | fs-extra |
| Category | File System |
| Weekly Downloads | 25M+ |
| License | MIT |
| Install | npm install fs-extra |
Related Packages
rimraf is a Node.js implementation of the Unix rm -rf command, providing cross-platform recursive di…
mkdirp is a Node.js utility that recursively creates directories, equivalent to mkdir -p in Unix. Gi…
glob is a library for matching files using glob patterns — the wildcard syntax familiar from shell c…
Chokidar is a fast, efficient file watching library for Node.js that provides a reliable cross-platf…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.