Skip to content

danlapid/worker-fs-mount

Repository files navigation

worker-fs-mount

Mount WorkerEntrypoints as virtual filesystems in Cloudflare Workers.

Try It Out

See it in action with an interactive filesystem explorer backed by a Durable Object:

git clone https://github.com/danlapid/worker-fs-mount
cd worker-fs-mount
pnpm install
pnpm example

Open http://localhost:8787 to create, edit, and delete files - all persisted in SQLite via a Durable Object, using standard node:fs/promises APIs.

Packages

Package Description
worker-fs-mount Main package - drop-in replacement for node:fs/promises with mount support
durable-object-fs Durable Object implementing a filesystem with SQLite storage
r2-fs R2-backed filesystem for large file storage
memory-fs In-memory filesystem for ephemeral/testing use

Quick Start

npm install worker-fs-mount

Add the alias to your wrangler.toml:

[alias]
"node:fs/promises" = "worker-fs-mount/fs"

Use it in your worker:

import { env } from 'cloudflare:workers';
import { mount } from 'worker-fs-mount';
import fs from 'node:fs/promises';

// Mount at module level using importable env
mount('/mnt/storage', env.STORAGE_SERVICE);

export default {
  async fetch(request) {
    // Standard fs operations work automatically
    await fs.writeFile('/mnt/storage/data.json', JSON.stringify({ hello: 'world' }));
    const content = await fs.readFile('/mnt/storage/data.json', 'utf8');

    return new Response(content);
  }
};

See the main package README for full documentation.

Development

pnpm install    # Install dependencies
pnpm build      # Build packages
pnpm test       # Run tests
pnpm typecheck  # Type check

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published