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:
Local development mode is in beta. Report any issues to GitHub Issues.
How Local Mode Works
Whenlocal: true is set, Alchemy:
- Skips cloud provider API calls for supported resources
- Starts local simulators (like Miniflare for Cloudflare Workers)
- Returns mock data for resources that donβt support local development
- 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:- Restarts your script when files change
- Reloads local workers with new code
- Preserves local state between reloads
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: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
- Testing - Write tests for your infrastructure
- Deployment - Deploy to production
- Custom Providers - Build custom resources with local support