Miniflare is a simulator for developing and testing Cloudflare Workers.
Originally started as an open-source project, Miniflare has been adopted by Cloudflare to become part of their ecosystem.
Installation per NPM:
npm install -g miniflare
CLI usage is really simple, and is highly configurable using one of its many flags:
$ miniflare worker.js
[mf:inf] Worker reloaded! (97B)
[mf:inf] Listening on :8787
[mf:inf] - http://127.0.0.1:8787
Alternatively you can also use it in your own JS code:
import { Miniflare } from "miniflare";
const mf = new Miniflare({
script: `
addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
});
`,
});
const res = await mf.dispatchFetch("http://localhost:8787/");
console.log(await res.text()); // Hello Miniflare!
🤔 Want to get started with Cloudflare Workers? This guide by Chris Ferdinandi should get you on track.