open-index/open-npm huggingface dataset:
npm package: @miniflare/cache
Description: Cache module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/cache`

Cache module for [Miniflare](https://github.com/cloudflare/miniflare): a fun,
full-featured, fully-local simulator for Cloudflare Workers. See
[✨ Cache](https://miniflare.dev/storage/cache) for more details.

## Example

```js
import { Cache } from "@miniflare/cache";
import { Response } from "@miniflare/core";
import { MemoryStorage } from "@miniflare/storage-memory";

const cache = new Cache(new MemoryStorage());

const key = "http://localhost";
const res = new Response("body", {
  headers: { "Cache-Control": "max-age=3600" },
});
await cache.put(key, res);

const cachedRes = await cache.match(key);
console.log(await cachedRes.text()); // body
```
npm package: @miniflare/cli-parser
Description: CLI option parsing module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/cli-parser`

CLI option parsing module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers. See
[💻 Using the CLI](https://miniflare.dev/get-started/cli) for more details.

## Example

```js
import { buildHelp, parseArgv } from "@miniflare/cli-parser";
import { BuildPlugin } from "@miniflare/core";
import { KVPlugin } from "@miniflare/kv";

const plugins = { BuildPlugin, KVPlugin };

const help = buildHelp(plugins, "exec");
console.log(help); // Usage: exec ...

const options = parseArgv(plugins, [
  "--build-command",
  "npm run build",
  "--kv-persist",
]);
console.log(options); // { buildCommand: "npm run build", kvPersist: true };
```
npm package: @miniflare/core
Description: Core module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/core`

Core module for [Miniflare](https://github.com/cloudflare/miniflare): a fun,
full-featured, fully-local simulator for Cloudflare Workers. See
[🧰 Using the API](https://miniflare.dev/get-started/api) for more details.

## Example

```js
import { CorePlugin, MiniflareCore } from "@miniflare/core";
import { KVPlugin } from "@miniflare/kv";
import { VMScriptRunner } from "@miniflare/runner-vm";
import { Log, LogLevel } from "@miniflare/shared";
import { MemoryStorage } from "@miniflare/storage-memory";

export class StorageFactory {
  storages = new Map();

  storage(namespace) {
    let storage = this.storages.get(namespace);
    if (storage) return storage;
    this.storages.set(namespace, (storage = new MemoryStorage()));
    return storage;
  }
}

const plugins = { CorePlugin, KVPlugin };
const ctx = {
  log: new Log(LogLevel.INFO),
  storageFactory: new StorageFactory(),
  scriptRunner: new VMScriptRunner(),
};

const mf = new MiniflareCore(plugins, ctx, {
  modules: true,
  script: `export default {
    async fetch(request, env) {
      return new Response(await env.TEST_NAMESPACE.get("key"));
    }
  }`,
  kvNamespaces: ["TEST_NAMESPACE"],
});

const { TEST_NAMESPACE } = await mf.getBindings();
await TEST_NAMESPACE.put("key", "value");

const res = await mf.dispatchFetch("http://localhost");
console.log(await res.text()); // value
```
npm package: @miniflare/d1
Description: Workers D1 module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: Glen Maddern
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/d1`

Workers D1 module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[📦 D1](https://miniflare.dev/storage/d1) for more details.

## Example

```js
import { createSQLiteDB } from "@miniflare/shared";
import { D1Database, D1DatabaseAPI } from "@miniflare/d1";

const sqliteDb = await createSQLiteDB(":memory:");
const db = new D1Database(new D1DatabaseAPI(sqliteDb));
await db.exec(
  `CREATE TABLE my_table (cid INTEGER PRIMARY KEY, name TEXT NOT NULL);`
);
const response = await db.prepare(`SELECT * FROM sqlite_schema`).all();
console.log(await response);
/*
{
  "success": true,
  "results": [
    {
      "type": "table",
      "name": "my_table",
      "tbl_name": "my_table",
      "rootpage": 2,
      "sql": "CREATE TABLE my_table (cid INTEGER PRIMARY KEY, name TEXT NOT NULL)"
    }
  ],
  ...
}
*/
```
npm package: @miniflare/durable-objects
Description: Durable Objects module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/durable-objects`

Durable Objects module for [Miniflare](https://github.com/cloudflare/miniflare):
a fun, full-featured, fully-local simulator for Cloudflare Workers. See
[📌 Durable Objects](https://miniflare.dev/storage/durable-objects) for more
details.

## Example

```js
import { DurableObjectStorage } from "@miniflare/durable-objects";
import { MemoryStorage } from "@miniflare/storage-memory";

const storage = new DurableObjectStorage(new MemoryStorage());
await storage.put("key", "value");
console.log(await storage.get("key")); // value
```
npm package: @miniflare/html-rewriter
Description: HTMLRewriter module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/html-rewriter`

HTMLRewriter module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[📄 HTMLRewriter](https://miniflare.dev/core/html-rewriter) for more details.

## Example

```js
import { Response } from "@miniflare/core";
import { HTMLRewriter } from "@miniflare/html-rewriter";

const rewriter = new HTMLRewriter().on("p", {
  element(element) {
    element.setInnerContent("new");
  },
});

const res = new Response("<p>old</p>");
const transformed = rewriter.transform(res);
console.log(await transformed.text()); // <p>new</p>
```
npm package: @miniflare/http-server
Description: HTTP server module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/http-server`

HTTP server module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[🧰 Using the API](https://miniflare.dev/get-started/api) for more details.

## Example

```js
import { CorePlugin, MiniflareCore } from "@miniflare/core";
import {
  HTTPPlugin,
  convertNodeRequest,
  createServer,
  startServer,
} from "@miniflare/http-server";
import { VMScriptRunner } from "@miniflare/runner-vm";
import { Log, LogLevel } from "@miniflare/shared";
import { MemoryStorage } from "@miniflare/storage-memory";
import http from "http";

// Converting Node.js http.IncomingMessage to Miniflare's Request
http.createServer(async (nodeReq, nodeRes) => {
  const req = await convertNodeRequest(nodeReq, "http://upstream", {
    forwardedProto: "http",
    realIp: "127.0.0.1",
    cf: { colo: "SFO" },
  });
  nodeRes.end(await req.text());
});

// Creating and starting HTTP servers
export class BadStorageFactory {
  storage() {
    throw new Error("This example shouldn't need storage!");
  }
}

const plugins = { CorePlugin, HTTPPlugin };
const ctx = {
  log: new Log(LogLevel.INFO),
  storageFactory: new BadStorageFactory(),
  scriptRunner: new VMScriptRunner(),
};

const mf = new MiniflareCore(plugins, ctx, {
  modules: true,
  script: `export default {
    async fetch(request, env) {
      return new Response("body");
    }
  }`,
  port: 5000,
});

// Start the server yourself...
const server = await createServer(mf);
// ...or get Miniflare to start it for you, logging the port
const server2 = await startServer(mf);
```
npm package: @miniflare/kv
Description: Workers KV module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/kv`

Workers KV module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[📦 KV](https://miniflare.dev/storage/kv) for more details.

## Example

```js
import { KVNamespace } from "@miniflare/kv";
import { MemoryStorage } from "@miniflare/storage-memory";

const ns = new KVNamespace(new MemoryStorage());
await ns.put("key", "value");
console.log(await ns.get("key")); // value
```
npm package: @miniflare/queues
Description: Workers Queues module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/queues`

Workers Queues module for [Miniflare](https://github.com/cloudflare/miniflare):
a fun, full-featured, fully-local simulator for Cloudflare Workers.
npm package: @miniflare/r2
Description: Workers R2 module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: CraigglesO
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/r2`

Workers R2 module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[🪣 R2](https://miniflare.dev/storage/r2) for more details.

## Example

```js
import { R2Bucket } from "@miniflare/r2";
import { MemoryStorage } from "@miniflare/storage-memory";

const r2 = new R2Bucket(new MemoryStorage());
await r2.put("key", "value");
const value = await r2.get("key");
console.log(await value.text()); // "value"
```
npm package: @miniflare/runner-vm
Description: VM script runner module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/runner-vm`

VM script runner module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers.

## Example

```js
import { VMScriptRunner } from "@miniflare/runner-vm";

const runner = new VMScriptRunner();
// Pass `console` into sandbox
const globalScope = { console };

// Run regular script
const blueprint1 = {
  code: 'console.log("hello")',
  filePath: "test.js",
};
await runner.run(globalScope, blueprint1); // hello

// Run module script
const blueprint2 = {
  code: 'import thing from "./thing.js"; console.log(thing);',
  filePath: "test.mjs",
};
const moduleRules = [{ type: "ESModule", include: /\.js$/ }];
// Assuming thing.js contains `"export default "thing";`...
await runner.run(globalScope, blueprint2, moduleRules); // thing

// Run module script with additional module
const blueprint3 = {
  code: `import additional from "__ADDITIONAL"; console.log(additional);`,
  filePath: "test.mjs",
};
const modules = {
  __ADDITIONAL: { default: "stuff" },
};
await runner.run(globalScope, blueprint3, moduleRules, modules); // stuff
```
npm package: @miniflare/scheduler
Description: Scheduler module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/scheduler`

Scheduler module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[⏰ Scheduled Events](https://miniflare.dev/core/scheduled) for more details.

## Example

```js
import { CorePlugin, MiniflareCore } from "@miniflare/core";
import { VMScriptRunner } from "@miniflare/runner-vm";
import { Log, LogLevel } from "@miniflare/shared";
import { SchedulerPlugin, startScheduler } from "@miniflare/scheduler";
import { MemoryStorage } from "@miniflare/storage-memory";

export class BadStorageFactory {
  storage() {
    throw new Error("This example shouldn't need storage!");
  }
}
const plugins = { CorePlugin, SchedulerPlugin };
const ctx = {
  log: new Log(LogLevel.INFO),
  storageFactory: new BadStorageFactory(),
  scriptRunner: new VMScriptRunner(),
};

const mf = new MiniflareCore(plugins, ctx, {
  modules: true,
  script: `export default {
    async scheduled(request, env) {
      console.log("tick");
    }
  }`,
  crons: ["* * * * *"],
});

const scheduler = await startScheduler(mf); // tick, tick, tick, ...
scheduler.dispose();
```
npm package: @miniflare/shared
Description: Shared utility module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/shared`

Shared utility module for [Miniflare](https://github.com/cloudflare/miniflare):
a fun, full-featured, fully-local simulator for Cloudflare Workers.
npm package: @miniflare/shared-test-environment
Description: Shared test environment utility module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/shared-test-environment`

Shared test environment utility module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers.
npm package: @miniflare/sites
Description: Workers Sites module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/sites`

Workers Sites module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[🌐 Workers Sites](https://miniflare.dev/storage/sites) for more details.

## Example

```js
import { CorePlugin, MiniflareCore } from "@miniflare/core";
import { VMScriptRunner } from "@miniflare/runner-vm";
import { Log, LogLevel } from "@miniflare/shared";
import { SitesPlugin } from "@miniflare/sites";

export class BadStorageFactory {
  storage() {
    throw new Error("This example shouldn't need storage!");
  }
}

const plugins = { CorePlugin, SitesPlugin };
const ctx = {
  log: new Log(LogLevel.INFO),
  storageFactory: new BadStorageFactory(),
  scriptRunner: new VMScriptRunner(),
};

const mf = new MiniflareCore(plugins, ctx, {
  modules: true,
  script: `export default {
    async fetch(request, env) {
      const url = new URL(request.url);
      const pathname = url.pathname.substring(1);
      return new Response(await env.__STATIC_CONTENT.get(pathname));
    }
  }`,
  sitePath: "./public",
});

// Assuming ./public/test.txt contains the text `test`
const res = await mf.dispatchFetch("http://localhost/test.txt");
console.log(await res.text()); // test
```
npm package: @miniflare/storage-file
Description: File-system storage module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/storage-file`

File-system storage module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers.

## Example

```js
import { KVNamespace } from "@miniflare/kv";
import { FileStorage } from "@miniflare/storage-file";

const ns = new KVNamespace(new FileStorage("./data"));
await ns.put("key", "value");
console.log(await ns.get("key")); // value
```
npm package: @miniflare/storage-memory
Description: In-memory storage module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/storage-memory`

In-memory storage module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers.

## Example

```js
import { KVNamespace } from "@miniflare/kv";
import { MemoryStorage } from "@miniflare/storage-memory";

const ns = new KVNamespace(new MemoryStorage());
await ns.put("key", "value");
console.log(await ns.get("key")); // value
```
npm package: @miniflare/storage-redis
Description: Redis storage module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/storage-redis`

Redis storage module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers.

## Example

```js
import { KVNamespace } from "@miniflare/kv";
import { RedisStorage } from "@miniflare/storage-redis";
import IORedis from "ioredis";

const redis = new IORedis("redis://localhost:6379");
const ns = new KVNamespace(new RedisStorage(redis, "namespace"));
await ns.put("key", "value");
console.log(await ns.get("key")); // value
```
npm package: @miniflare/watcher
Description: File-system watcher module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/watcher`

File-system watcher module for
[Miniflare](https://github.com/cloudflare/miniflare): a fun, full-featured,
fully-local simulator for Cloudflare Workers.

## Example

```js
import { Watcher } from "@miniflare/watcher";

const watcher = new Watcher((changedPath) => {
  console.log(changedPath); // Absolute path logged on create, change, delete
});

// Add recursive directory watcher
watcher.watch("./dir");

// Add file watchers
watcher.watch(/* any iterable */ ["./file1.txt", "./file2.txt"]);

// Remove watchers
watcher.unwatch("./file1.txt");

// Remove all watchers
watcher.dispose();
```
npm package: @miniflare/web-sockets
Description: WebSocket module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Author: MrBBot
Latest version: 2.14.4
Deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4

# `@miniflare/web-sockets`

WebSocket module for [Miniflare](https://github.com/cloudflare/miniflare): a
fun, full-featured, fully-local simulator for Cloudflare Workers. See
[✉️ WebSockets](https://miniflare.dev/core/web-sockets) for more details.

## Example

```js
import StandardWebSocket from "ws";
import { WebSocketPair, coupleWebSocket } from "@miniflare/web-sockets";

const [webSocket1, webSocket2] = Object.values(new WebSocketPair());

// Manually accept the first WebSocket
webSocket1.accept();
webSocket1.addEventListener("message", (event) => {
  console.log(event.data);
});
webSocket1.send("hello");

// Couple (forward messages from/to) the second WebSocket with a real WebSocket
const ws = new StandardWebSocket("ws://...");
coupleWebSocket(ws, webSocket2);
```