{"library":"memory-fs","title":"In-Memory Filesystem (memory-fs)","description":"memory-fs provides a simple, synchronous and asynchronous, in-memory filesystem abstraction, designed to hold data entirely within a JavaScript object. It mirrors a subset of the Node.js `fs` module API, making it suitable for scenarios where persistent disk I/O is undesirable or impractical, such as build tools, bundlers, and testing environments. The current stable version, 0.5.0, was released in 2017. While not actively developing new features, it is a critical, stable dependency for projects like Webpack, which relies on it for fast, transient asset compilation. Its primary differentiator is its complete in-memory operation and direct API compatibility with many standard `fs` methods, offering a performant alternative to disk-based operations for temporary file storage.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install memory-fs"],"cli":null},"imports":["const MemoryFileSystem = require('memory-fs');","const fs = new MemoryFileSystem();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const MemoryFileSystem = require('memory-fs');\nconst fs = new MemoryFileSystem(); // Optionally pass an initial JavaScript object, e.g., { 'src': { 'main.js': 'console.log(\"Hello\");' } }\n\n// Create directories\nfs.mkdirpSync(\"/a/test/dir\");\nconsole.log('Created /a/test/dir');\n\n// Write and read a file\nconst filePath = \"/a/test/dir/file.txt\";\nfs.writeFileSync(filePath, \"Hello World from memory-fs\");\nconsole.log(`Content of ${filePath}: ${fs.readFileSync(filePath, 'utf8')}`);\n\n// Async file unlink\nfs.unlink(filePath, function(err) {\n  if (err) {\n    console.error(`Error unlinking file: ${err.message}`);\n    return;\n  }\n  console.log(`${filePath} unlinked successfully.`);\n});\n\n// List directory contents\nconsole.log(`Contents of /a/test: ${fs.readdirSync(\"/a/test\")}`);\n\n// Get file/directory stats\nconst stats = fs.statSync(\"/a/test/dir\");\nconsole.log(`/a/test/dir is a directory: ${stats.isDirectory()}`);\n\n// Clean up directory\nfs.rmdirSync(\"/a/test/dir\");\nconsole.log('Removed /a/test/dir');","lang":"javascript","description":"Demonstrates basic synchronous and asynchronous file operations (create, write, read, delete, list, stat) using the `memory-fs` API.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}