This article assumes that you’ll be deploying Workers applications to your
workers.devsubdomain - if you want to use Wrangler to deploy Workers applications to your own domain name, you’ll need to configure your
wrangler.tomlslightly differently. For more information, see “Deploying To Your Domain”.
You’ll need a few values from your Cloudflare account to deploy code to Cloudflare Workers:
Follow this guide to find these values for your account.
To configure Wrangler to deploy to your Cloudflare Workers account, set up your default credentials via the
config subcommand. You should only need to do this once:
$ wrangler config <email> <global_api_key>
To configure your project, complete the
wrangler.toml file at the root of the generated project. This file contains the information wrangler needs to connect to the Cloudflare Workers API, and publish your code.
The name field in this config file, which will map to your application’s deploy name (e.g.
my-worker.mysubdomain.workers.dev), should have a default value already filled in – feel free to change it, if you’d like.
Fill in the
account_id field with the value found in your dashboard.
# wrangler.toml # The name of your Workers application name = "my-worker" # Your Cloudflare account ID account_id = "$yourAccountId" # The kind of application you're deploying to Cloudflare type = "webpack"
worker.js contains the actual code that you’ll deploy to Workers. Let’s use two more Wrangler commands to build your project, and preview it:
$ wrangler build $ wrangler preview
build command will install the necessary dependencies for your project, and compile it to make it ready for deployment. The
build command will also notify you of any build warnings before deployment.
preview command will take your built Worker project and upload it to a unique URL at cloudflareworkers.com. This means that you can actually test your project with our Workers runtime, and optionally, you can share this URL so that other users can test your Worker!
With your project configured, it’s time to publish it! Wrangler has a built-in command for uploading your script, generating the route that corresponds to your
wrangler.toml file, and wiring them together. If that sounds complicated, don’t worry – we’ve made it really easy:
$ wrangler publish
Your Worker will be uploaded and deployed to the route you specified in your config file. To ensure that everything deployed correctly, go to the URL specified at the end of the publishing process – you should see your Worker running as expected!
This is just the beginning of what you can do with Cloudflare Workers. If you’d like to dive deeper into building projects with Cloudflare Workers, check out the full-length tutorials below: