Getting Started
Alchemy is a simple TypeScript script that you run to deploy infrastructure. All you need is a Node.js runtime and a Cloudflare account to get started.
-
Create your project
Start by creating a new project and installing Alchemy.
Terminal window mkdir my-alchemy-appcd my-alchemy-appTerminal window bun init -ybun add alchemybun add -g wranglerTerminal window npm init -ynpm install alchemynpm install -g wranglerTerminal window pnpm initpnpm add alchemypnpm add -g wranglerTerminal window yarn init -yyarn add alchemyyarn global add wrangler -
Login to Cloudflare
Authenticate with your Cloudflare account.
Terminal window bun wrangler loginTerminal window npx wrangler loginTerminal window pnpm wrangler loginTerminal window yarn wrangler login -
Create your infrastructure
Create
alchemy.run.ts
with a simple Worker:import alchemy from "alchemy";import { Worker } from "alchemy/cloudflare";const app = await alchemy("my-first-app");const worker = await Worker("hello-worker", {entrypoint: "./src/worker.ts",});console.log(`Worker deployed at: ${worker.url}`);await app.finalize(); -
Create your worker code
Create
src/worker.ts
:export default {async fetch(request: Request): Promise<Response> {return Response.json({message: "Hello from Alchemy!",timestamp: new Date().toISOString(),});},}; -
Start development mode
Run with
--watch
for hot reloading during development:Terminal window bun --watch ./alchemy.run.tsTerminal window npx tsx --watch ./alchemy.run.tsTerminal window pnpm tsx --watch ./alchemy.run.tsTerminal window yarn tsx --watch ./alchemy.run.tsYour worker will be available locally with live updates as you edit your code.
-
Make a change
Update your worker message in
src/worker.ts
:message: "Hello from Alchemy! 🧪",Save the file and see the change reflected immediately.
-
Deploy to production
Remove
--watch
to deploy to Cloudflare:Terminal window bun ./alchemy.run.tsTerminal window npx tsx ./alchemy.run.tsTerminal window pnpm tsx ./alchemy.run.tsTerminal window yarn tsx ./alchemy.run.tsVisit the URL to see your worker live on Cloudflare’s edge network.
-
(Optional) Tear down
Pass
--destroy
to delete all of the resources:Terminal window bun ./alchemy.run.ts --destroyTerminal window npx tsx ./alchemy.run.ts --destroyTerminal window pnpm tsx ./alchemy.run.ts --destroyTerminal window yarn tsx ./alchemy.run.ts --destroy
You’ve successfully deployed your first Cloudflare Worker with Alchemy! Here are some next steps:
- Deploy a ViteJS site to Cloudflare - Build full-stack applications
- Learn about Cloudflare Workers - Advanced worker features
- Build your own Custom Resource - Extend Alchemy