2 min read

Setup Working Environment for Developing Cloudflare Workers Apps

I know most of us just want to dive into development when we see new tool or framework. But then there is so many comebacks for things that we need to do at the beginning. In this post I will…
Setup Working Environment for Developing Cloudflare Workers Apps

I know most of us just want to dive into development when we see new tool or framework. But then there is so many comebacks for things that we need to do at the beginning. In this post I will describe my working environment for development of Workers.

IDE (Integrated Development Environment)

I usually use Visual Studio Code. It has great extension library but you don’t need anything special for now. You can download it here. https://code.visualstudio.com/

Cloudflare Wrangler

Wrangler is a CLI tool designed for development of workers. Here is its homepage. And you can find GitHub page here.

Quick Installation of Wrangler

npm i @cloudflare/wrangler -g

That is for installation but you need to configure your environment for publishing. The configuration file is created in a .wrangler directory in your computer's home directory. You need to add account email and global API Key to this file.

email = "email[at]example.com"
api_key = "XXXXXKEYXXXXXXX"

You can get your API Key from CF Dashboard. Go to Dashboard>Profile>API Tokens and get ‘ Global API Key’.

Generate From Template

After these quick installations and configurations you can generate your first workers app. I recommend to use template for understand path structure and configurations.

wrangler generate

This command on terminal will create first basic workers app for you. It actually clones this GitHub repo. https://github.com/cloudflare/worker-template But it is enough for a start.

There are 3 main files in our folder now. index.jswrangler.toml and package.json.

index.js is your main javascript file. CF will try to run this file first. You can change this file’s name or add more files to environment.
package.json is your main configuration file for workers app. You can add version, name of your app, depended packages or change main file name on this file.
wrangler.toml is configuration of environments and deployment. You can define type of your app, route configuration, zone info, KV info, etc. here.

All set

After these steps you are all set to start development of workers app. You may start with Playground if you like to start simple and don’t want to set up anything.