Remix.run + Cloudflare worker environmental variables

Viewed 43

I'm trying run Remix.run with Cloudflare workers. How might I access environmental variables related to Cloudflare data persistence services (such as D1) in Remix.run data loader functions?

I have "bound" the worker via wrangler.toml and can access the service via wrangler.

[[ d1_databases ]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "Example"
database_id = "123-456-789"

I'm able to access other environmental variables from the global scope using .env.vars but can't seem to access DB.

1 Answers

In Cloudflare Workers, environment variables are exposed on the global object. I recommend making them all caps.

declare var DATABASE_ID: string
console.log(DATABASE_ID)
Related