Skip to main content

Local Development

Alchemy supports local development mode where resources can be simulated locally using tools like Miniflare for Cloudflare Workers. This allows you to iterate quickly without deploying to production.

Enabling Local Mode

Run your Alchemy script with the --local or --dev flag:
Or enable it programmatically:
Local development mode is in beta. Report any issues to GitHub Issues.

How Local Mode Works

When local: true is set, Alchemy:
  1. Skips cloud provider API calls for supported resources
  2. Starts local simulators (like Miniflare for Cloudflare Workers)
  3. Returns mock data for resources that don’t support local development
  4. Binds local resources together so they can interact

Supported Resources

Cloudflare Workers

Workers run locally using Miniflare:

Cloudflare D1 Database

D1 databases use local SQLite:

Cloudflare KV, R2, and More

Most Cloudflare resources work locally through Miniflare:

Watch Mode

Combine local mode with watch mode for automatic reloading:
Or use the Alchemy CLI:
This automatically:
  • Restarts your script when files change
  • Reloads local workers with new code
  • Preserves local state between reloads
Watch mode is perfect for rapid iteration during development.

Testing Local Resources

Once your resources are running locally, you can test them:

HTTP Requests

Programmatic Testing

Local vs Production Differences

Resource Behavior

Some resources behave differently in local mode:

State Storage

In local mode, state is still persisted to .alchemy/ but resources run locally:

Conditional Local Behavior

Check if running in local mode within resources:

Environment Variables

Use different environment variables for local vs production:
alchemy.run.ts

Tunneling

Create a public URL for your local resources using tunnels:
This creates a public URL you can share:
Use tunnels to test webhooks and integrations that require public URLs.

Example: Full Local Development Setup

Troubleshooting

Port Already in Use

If port 8787 is already in use, specify a different port:

Local State Not Persisting

Local state is stored in .alchemy/ - make sure this directory is not gitignored (only .alchemy/*.sqlite should be ignored):

Resources Not Reloading

Ensure you’re using --watch or bun --watch:

Best Practices

Next Steps