class

vfs.MemoryProvider

class MemoryProvider

The default in-memory provider. Stores files, directories, and symbolic links in a Map-backed tree, supports symlinks (supportsSymlinks === true), and supports watching (supportsWatch === true).

  • setReadOnly(): void;

    Locks the provider into read-only mode. Subsequent writes through any VirtualFileSystem using this provider throw EROFS. There is no way to revert the provider to writable.

    const vfs = require('node:vfs');
    
    const provider = new vfs.MemoryProvider();
    const myVfs = vfs.create(provider);
    myVfs.writeFileSync('/seed.txt', 'initial');
    
    provider.setReadOnly();
    
    myVfs.writeFileSync('/x.txt', 'fail'); // throws EROFS