Start a New Worker
Follow these steps to setup denoflare serve
to run from a config file. This assumes you've already installed the denoflare CLI.
Create a project folder. Add an entry script:
// index.ts export default { async fetch(request: Request, env: any) { try { return new Response('hi') } catch (e) { return new Response(e.message) } }, }
Create a file named
.denoflare
. Paste in the following config:// .denoflare { "$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.6.0/common/config.schema.json", "scripts": { "hello-local": { "path": "index.ts", "localPort": 3030 } }, "profiles": { "account1": { // your cloudflare account id "accountId": "<YOUR ACCOUNT ID>", // your cloudflare api token "apiToken": "<YOUR API TOKEN>" } } }
In order for the configuration to work, you have to enter your accountId and apiToken from your Cloudflare Workers dashboard .
Start local development by running
denoflare serve hello-local
, wherehello-local
is the name of the script in the configuration file.Let's make sure it works. Open http://localhost:3030 . You should see
hi
.Now change the response string to
Hello, World!
and save the file. Denoflare will automatically compile the changes! Refresh the browser to confirm.That's all it takes. You're ready to begin building your worker!