{"library":"memfs","title":"In-Memory File System","description":"memfs is a JavaScript library that provides an in-memory file system, designed to be highly compatible with Node.js's native `fs` module API and the browser's File System (Access) API. It serves as a robust tool for testing, mocking file system operations, and creating isolated virtual environments across both Node.js and modern browser runtimes. The current stable version is `4.57.2`. The project exhibits an active release cadence, with frequent patch and minor updates, as indicated by the rapid succession of releases between January and April 2026. Its key differentiators include comprehensive dual API compatibility, built-in TypeScript support, and helpful utilities like directory snapshots, making it a versatile solution for cross-environment file system virtualization.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install memfs"],"cli":null},"imports":["import { fs } from 'memfs';","import { fsa } from 'memfs';","import { Volume } from 'memfs';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { fs } from 'memfs';\nimport path from 'path'; // Recommended for robust path handling\n\n// memfs exports an 'fs' object that mimics Node.js fs module.\n// For creating a new, isolated volume, you'd typically instantiate Volume:\n// const vol = Volume.fromJSON({ '/foo': 'bar' });\n// However, 'fs' export provides a convenient default instance.\nconst volFs = fs; \n\n// Write a file\nvolFs.writeFileSync('/hello.txt', 'Hello, World!');\nconsole.log('File written: /hello.txt');\n\n// Read a file\nconst content = volFs.readFileSync('/hello.txt', 'utf-8');\nconsole.log('Content of /hello.txt:', content);\n\n// Create a directory\nvolFs.mkdirSync('/mydir');\nconsole.log('Directory created: /mydir');\n\n// Create a nested file\nvolFs.writeFileSync('/mydir/nested.txt', 'Nested content here.');\nconsole.log('File written: /mydir/nested.txt');\n\n// List directory contents\nconsole.log('Contents of /:', volFs.readdirSync('/'));\nconsole.log('Contents of /mydir:', volFs.readdirSync('/mydir'));\n\n// Example using path.join for cross-platform path construction\nconst filePath = path.join('/', 'mydir', 'nested.txt');\nconsole.log('Joined path:', filePath);\nconsole.log('Content via joined path:', volFs.readFileSync(filePath, 'utf-8'));\n","lang":"typescript","description":"Demonstrates basic file and directory operations using the Node.js `fs` compatible API provided by `memfs`, including writing, reading, creating directories, and listing contents within an in-memory file system.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}