memfs
In-memory file system with Node.js fs API and browser File System (Access) API.

Overview
memfs is a JavaScript library that implements an in-memory file system compatible with Node.js fs module and the browser File System (Access) API. Use it for testing, mocking file systems, or creating virtual file systems in both Node.js and browser environments.
Installation
npm install memfs
Quick Start
Node.js fs API
import { fs } from 'memfs';
fs.writeFileSync('/hello.txt', 'Hello, World!');
const content = fs.readFileSync('/hello.txt', 'utf-8');
console.log(content);
fs.mkdirSync('/mydir');
console.log(fs.readdirSync('/'));
Browser File System API
import { fsa } from 'memfs';
const root = await fsa.getRoot();
const file = await root.getFileHandle('hello.txt', { create: true });
const writable = await file.createWritable();
await writable.write('Hello, World!');
await writable.close();
const readable = await file.getFile();
const text = await readable.text();
console.log(text);
Features
- Node.js
fs module API compatibility
- Browser File System (Access) API implementation
- Adapters between
fs and File System API
- Directory snapshots and tree printing utilities
- Works in Node.js and modern browsers
- TypeScript support
Documentation
For detailed documentation and more examples, visit the main project page.
License
Apache 2.0