Search code examples
javascriptcloudflareworker

How to add JavaScript code to a Cloudflare Worker?


Cloudflare's docs and blog posts clearly state they support JavaScript code in their Workers, but I can't find any way to add JavaScript or access the editor?

Specifically I'm trying to build a maintenance page via their Workers API, following this (rather old) guide.

I've been looking for a half hour now and can't find any way to add JS code to Workers for my life. Can anyone point me in the right direction?


Solution

  • If you need to use a web editor, then you can use the Service environments (Quick Edit) feature. Just create a new service, then click the blue Quick Edit button under Worker in the Resources tab.

    However, you should prefer to use the Wrangler CLI. With Wrangler, you create an NPM project on your local machine that can be pushed to Cloudflare workers when you're ready to deploy. Wrangler also lets you test on your local machine. The Cloudflare Workers documentation guides you through using the Wrangler CLI in depth.