Run (or test) a Cloudflare Worker Locally. If you are looking for a project that will quickly help you bootstrap your worker, take a look at create-cloudflare-worker
$ npm install -g cloudflare-worker-local
$ cloudflare-worker-local /path/to/worker.js localhost:3000 4000
Listening on Port 4000 and forwarding requests to http://localhost:3000/
It is possible to use nodemon to automatically reload the worker
$ npm install -g nodemon
$ nodemon --watch /path/to/worker.js --signal SIGHUP --exec 'cloudflare-worker-local /path/to/worker.js localhost:3000 4000'
cloudflare-worker-local
can be used to unit test a cloudflare worker. Please see This Example. You may also be interested in create-cloudflare-worker
- Anything in Node.js scope by default (Object, Array)
- Anything provided by fetch (fetch, Request, Response, Headers)
- WHATWG URL
- console
- btoa / atob
- crypto.subtle
- Cloudflare key value store if you pass in the KV_NAMESPACE environment variable
- ... this list should probably have more things
- Tejas Dinkar (@gja)
- Jeremy Danyow (@jdanyow)
- Support WASM
- Support CPU timeouts
- Better Examples
- NUM_WORKERS - Specifies the number of node workers (default 1, to get KV Working in memory)
- KV_NAMESPACES - A comma separated list of keyspaces. (ex: MY_STORE,ANOTHER_STORE)