Getting started
Build and run a small Effect program whose files exist only in memory. You will keep using Effect's standard
FileSystem service and select the virtual implementation when the program runs.
Install the memory adapter
Install the adapter. npm installs its declared Effect peer dependency:
npm install @effect-vfs/memory@latest
npm install "@effect/platform-bun@$(npm view @effect-vfs/memory peerDependencies.effect)"The packages are ESM-only, so your project must support ES modules.
Run a filesystem program
Write against Effect's FileSystem.FileSystem service, then provide MemoryFileSystem.layer when you run the program. The layer builds its own volume and requires an Effect Crypto service:
import * as BunCrypto from "@effect/platform-bun/BunCrypto"
import { MemoryFileSystem } from "@effect-vfs/memory"
import { Effect, FileSystem } from "effect"
const loadSettings = Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem
yield* fs.writeFileString(
"/settings.json",
JSON.stringify({ mode: "preview" })
)
return yield* fs.readFileString("/settings.json")
})
const settings = await Effect.runPromise(
loadSettings.pipe(Effect.provide(MemoryFileSystem.layer), Effect.provide(BunCrypto.layer))
)
console.log(settings)The program prints:
{"mode":"preview"}No host file is created. MemoryFileSystem.layer supplies a fresh virtual volume with / as its working directory
and an empty /tmp directory.
The program can use another FileSystem.FileSystem implementation without changing loadSettings.
Choose the next step
- Test with an isolated filesystem when you need disposable state for repeatable tests.
- Choose a package before using volumes, snapshots, or SQLite checkpoints directly.
- Open the
MemoryFileSystemAPI reference for the complete adapter surface.