© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•4mo ago•
5 replies
msy

Monorepo on Cloudflare Workers: Unable to pass down Environment Variables

Hey guys, new to Cloudflare Workers, Wrangler, and D1.

Trying to scaffold out to use Cloudflare Workers in a monorepo structure, and get it deployed:

Monorepo Structure:
- apps/
- - web/
- - server/
- packages
- - db/
- - auth/
- - .../
- apps/
- - web/
- - server/
- packages
- - db/
- - auth/
- - .../

I'm using Vite (React), Drizzle, Better-Auth, and Hono.

apps/server/wrangler.toml
apps/server/wrangler.toml
:
name = "..."
main = "src/index.ts"
compatibility_date = "2025-04-03"
compatibility_flags = ["nodejs_compat"]

[[d1_databases]]
binding = "DATABASE_URL"
database_id = "4a72636b-dcca-4307-9530-eadca0029da4"
migrations_dir = "../../packages/db/src/migrations"
database_name = "db-name"

[vars]
CORS_ORIGIN = "..."

[vars.prod]
CORS_ORIGIN = "..."
name = "..."
main = "src/index.ts"
compatibility_date = "2025-04-03"
compatibility_flags = ["nodejs_compat"]

[[d1_databases]]
binding = "DATABASE_URL"
database_id = "4a72636b-dcca-4307-9530-eadca0029da4"
migrations_dir = "../../packages/db/src/migrations"
database_name = "db-name"

[vars]
CORS_ORIGIN = "..."

[vars.prod]
CORS_ORIGIN = "..."


apps/web/wrangler.toml
apps/web/wrangler.toml
:
name = "..."
compatibility_date = "2025-04-03"

[assets]
not_found_handling = "single-page-application"

[vars]
VITE_SERVER_URL = "http://localhost:3000"

[vars.prod]
VITE_SERVER_URL = "..."
name = "..."
compatibility_date = "2025-04-03"

[assets]
not_found_handling = "single-page-application"

[vars]
VITE_SERVER_URL = "http://localhost:3000"

[vars.prod]
VITE_SERVER_URL = "..."


I had a few questions:

- How does my
web/
web/
monorepo get access to the workers environment variables?
When I check the settings under Environment Variables, it says that static assets do not have access to environment variables.
- How does my
db/
db/
package (which is Drizzle), gain access to the D1 instance? This is mainly for running the cli, i.e. migration, pushing.
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Confused about prod workers environment variables
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
How to access environment variables in Cloudflare Workers when using RPC binding
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
15mo ago
Deployed website unable to find environment variables set on Worker
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago