---
title: Deployment guide for Cloudflare Workers
slug: feature-experimentation/docs/deployment-guide-for-cloudflare-workers
docTags: 
createdAt: 2026-08-05T20:39:51.000Z
---

## Prerequisites

You must [install the Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/install-and-update/) to manage Cloudflare Workers.

## Get started

### Generate a project

Generate a project using the template hosted on GitHub:

```shell
wrangler generate {projectname} REPOSITORY PLACEHOLDER
```

### Configure `wrangler.toml` file

1. Rename the `wrangler.toml.template` file in the root of the project to `wrangler.toml`.
2. Update the variables inside by adding your `account_id` and `kv_namespace(s)` if you plan on using the KV Store for datafile and flag keys management.

**wrangler.toml.template file example:**

```javascript
#:schema node_modules/wrangler/config-schema.json
name = "optly-hybrid-agent"
main = "src/index.js"
compatibility_date = "2024-05-02"
compatibility_flags = ["nodejs_compat"]
account_id = "YOUR ACCOUNT ID HERE"
workers_dev = true
route = "YOUR ROUTE GOES HERE"
kv_namespaces = [
  {
    binding = "OPTLY_HYBRID_AGENT_KV", 
    id = "KV NAMESPACE ID GOES HERE", 
    preview_id = "KV PREVIEW NAMESPACE ID GOES HERE"
  },
  {
    binding = "OPTLY_HYBRID_AGENT_UPS_KV", 
    id = "KV USER PROFILE NAMESPACE ID GOES HERE", 
    preview_id = "KV USER PROFILE PREVIEW NAMESPACE ID GOES HERE"
  }
]

[vars]
# Supported: "debug, debugExt, info, error"
LOG_LEVEL = "debug"
# TESTING_FLAG_DEBUG = "INDIVIDUAL FX FLAG KEY FOR TESTING GOES HERE"
```

## Update Project Configuration

Update the project configuration settings in the `requestConfig.js` file located in the *config* directory. See the [requestConfig.js documentation](docId\:h6cIa7TJ2bWh53yIqslL5) for information.

## Install node modules

Install the necessary Node.js modules using the following command:

```shell
npm install
```

## Test and debug locally

Using Wrangler CLI, you can test and debug the worker locally. This supports local debugging and lets you set breakpoints.

```shell
wrangler dev
```

## Visual Studio (VS) Code launch configuration

The following is an example VS Code launch configuration that attaches the VS Code debugger to the local development Cloudflare Edge Worker for debugging purposes.

```json
{  
  "version": "0.2.0",  
  "configurations": \[  
    {  
      "type": "pwa-node",  
      "request": "attach",  
      "name": "Attach to Cloudflare Worker",  
      "skipFiles": ["<node_internals>/**"],  
      "port": 9229,  
      "localRoot": "${workspaceFolder}",  
      "remoteRoot": "/src"  
    }  
  ] 
}
```

## Deploy the Cloudflare Worker

To deploy the Worker to Cloudflare, run the following:

```shell
wrangler publish
```

### Tail logs for debugging (optional)

To debug and tail the logs when accessing Workers deployed on Cloudflare, run the following:

```shell
wrangler tail -f pretty
```
