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 and its exact Effect peer version:

npm install @effect-vfs/memory effect@4.0.0-rc.114

The packages are ESM-only, so your project must support ES modules.

Write a filesystem program

Create a program that requests FileSystem.FileSystem, writes a JSON file, and reads it back:

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")
})

There is nothing virtual-filesystem-specific in this program. It can run with any implementation of Effect's FileSystem service.

Provide the in-memory filesystem

Provide MemoryFileSystem.layer when you run the program:

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))
)
 
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.

Choose the next step