> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/alchemy-run/alchemy/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Deploy your first Cloudflare Worker with Alchemy in under 5 minutes

Get up and running with Alchemy by deploying a Cloudflare Worker with storage and a database.

## Prerequisites

* Node.js 18+ or Bun
* A Cloudflare account with an API token ([create one here](https://dash.cloudflare.com/profile/api-tokens))

## Install Alchemy

<Steps>
  <Step title="Create a new project">
    Create a new directory and initialize your project:

    <CodeGroup>
      ```bash npm theme={null}
      mkdir my-alchemy-app
      cd my-alchemy-app
      npm init -y
      ```

      ```bash yarn theme={null}
      mkdir my-alchemy-app
      cd my-alchemy-app
      yarn init -y
      ```

      ```bash pnpm theme={null}
      mkdir my-alchemy-app
      cd my-alchemy-app
      pnpm init
      ```

      ```bash bun theme={null}
      mkdir my-alchemy-app
      cd my-alchemy-app
      bun init -y
      ```
    </CodeGroup>
  </Step>

  <Step title="Install Alchemy">
    <CodeGroup>
      ```bash npm theme={null}
      npm install alchemy
      ```

      ```bash yarn theme={null}
      yarn add alchemy
      ```

      ```bash pnpm theme={null}
      pnpm add alchemy
      ```

      ```bash bun theme={null}
      bun add alchemy
      ```
    </CodeGroup>
  </Step>

  <Step title="Set up credentials">
    Create a `.env` file with your Cloudflare credentials:

    ```bash theme={null}
    CLOUDFLARE_API_TOKEN=your-api-token
    CLOUDFLARE_ACCOUNT_ID=your-account-id
    ```

    <Tip>
      Find your Account ID in the Cloudflare dashboard URL: `dash.cloudflare.com/<account-id>`
    </Tip>
  </Step>
</Steps>

## Create your first deployment

<Steps>
  <Step title="Create the Worker code">
    Create a file `src/worker.ts` with your Worker code:

    ```typescript src/worker.ts theme={null}
    export default {
      async fetch(request: Request, env: Env) {
        const url = new URL(request.url);
        
        // Get visitor count from KV
        const count = parseInt((await env.VISITS.get("count")) || "0");
        const newCount = count + 1;
        await env.VISITS.put("count", newCount.toString());
        
        // Store visit info in R2
        await env.STORAGE.put(
          `visit-${Date.now()}.json`,
          JSON.stringify({
            timestamp: Date.now(),
            url: url.pathname,
            count: newCount,
          })
        );
        
        return Response.json({
          message: "Hello from Alchemy!",
          visits: newCount,
        });
      },
    };

    interface Env {
      VISITS: KVNamespace;
      STORAGE: R2Bucket;
    }
    ```
  </Step>

  <Step title="Create the deployment script">
    Create `alchemy.run.ts` to define your infrastructure:

    ```typescript alchemy.run.ts theme={null}
    import alchemy from "alchemy";
    import { Worker, KVNamespace, R2Bucket } from "alchemy/cloudflare";

    const app = await alchemy("my-app");

    // Create KV namespace for visit counting
    const visits = await KVNamespace("visits", {
      name: `${app.name}-${app.stage}-visits`,
    });

    // Create R2 bucket for storing visit data
    const storage = await R2Bucket("storage", {
      name: `${app.name}-${app.stage}-storage`,
    });

    // Deploy the Worker
    const worker = await Worker("worker", {
      name: `${app.name}-${app.stage}-worker`,
      entrypoint: "./src/worker.ts",
      bindings: {
        VISITS: visits,
        STORAGE: storage,
      },
      url: true, // Enable workers.dev subdomain
    });

    console.log(`Worker deployed to: ${worker.url}`);

    await app.finalize();
    ```
  </Step>

  <Step title="Deploy to Cloudflare">
    Run the deployment script:

    <CodeGroup>
      ```bash npm theme={null}
      npx tsx alchemy.run.ts
      ```

      ```bash yarn theme={null}
      yarn tsx alchemy.run.ts
      ```

      ```bash pnpm theme={null}
      pnpm tsx alchemy.run.ts
      ```

      ```bash bun theme={null}
      bun ./alchemy.run.ts
      ```
    </CodeGroup>

    You should see output like:

    ```
    Worker deployed to: https://my-app-dev-worker.username.workers.dev
    ```
  </Step>

  <Step title="Test your Worker">
    Visit the URL in your browser or use curl:

    ```bash theme={null}
    curl https://my-app-dev-worker.username.workers.dev
    ```

    Response:

    ```json theme={null}
    {
      "message": "Hello from Alchemy!",
      "visits": 1
    }
    ```
  </Step>
</Steps>

## Make updates

Update your Worker code in `src/worker.ts`, then re-run the deployment script. Alchemy will detect the changes and update only what's necessary:

<CodeGroup>
  ```bash npm theme={null}
  npx tsx alchemy.run.ts
  ```

  ```bash bun theme={null}
  bun ./alchemy.run.ts
  ```
</CodeGroup>

## Tear down

To delete all resources:

<CodeGroup>
  ```bash npm theme={null}
  npx tsx alchemy.run.ts --destroy
  ```

  ```bash yarn theme={null}
  yarn tsx alchemy.run.ts --destroy
  ```

  ```bash pnpm theme={null}
  pnpm tsx alchemy.run.ts --destroy
  ```

  ```bash bun theme={null}
  bun ./alchemy.run.ts --destroy
  ```
</CodeGroup>

## What's next?

<CardGroup cols={2}>
  <Card title="Core concepts" icon="book" href="/concepts/resources">
    Learn about resources, scopes, and lifecycle
  </Card>

  <Card title="Local development" icon="laptop-code" href="/guides/local-development">
    Develop and test locally with Miniflare
  </Card>

  <Card title="Manage secrets" icon="key" href="/guides/managing-secrets">
    Securely handle API keys and credentials
  </Card>

  <Card title="More examples" icon="code" href="/examples/cloudflare-worker">
    Browse complete examples
  </Card>
</CardGroup>
