Workers - Access your Worker's environment variables from process.env
1y ago
Source
CloudflareWorkers - Access your Worker's environment variables from process.envcloudflare.comYou can now access environment variables and secrets on process.env when using the nodejs_compat compatibility flag . const apiClient = ApiClient . new ( { apiKey : process . env . API_KEY } ) ; const LOG_LEVEL = process . env . LOG_LEVEL || "info" ; In Node.js, environment variables are exposed via the global process.env object. Some libraries assume that this object will be populated, and many developers may be used to accessing variables in this way. Previously, the process.env object was always empty unless written to in Worker code. This could cause unexpected errors or friction when developing Workers using code previously written for Node.js. Now, environment variables , secrets , and version metadata can all be accessed on process.env . To opt-in to the new process.env behaviour now, add the nodejs_compat_populate_process_env compatibility flag to your wrangler.json configuration: wrangler.jsonc { // Rest of your configuration // Add "nodejs_compat_populate_process_env" to your compatibility_flags array " compatibility_flags " : [ "nodejs_compat" , "nodejs_compat_populate_process_env" ], // Rest of your configuration wrangler.toml compatibility_flags = [ "nodejs_compat" , "nodejs_compat_populate_process_env" ] After April 1, 2025, populating process.env will become the default behavior when both nodejs_compat is enabled and your Worker's compatibility_date is after "2025-04-01".
You might also wanna read
Cloudflare expands AI bot management tools with granular traffic controls for all customers
Cloudflare is celebrating the second "Content Independence Day" by expanding AI traffic management options for all website owners. Building
Workers - Simpler runtime types with @cloudflare/workers-types v5
Cloudflare·2d ago
Workers - Work across multiple accounts with Wrangler auth profiles
Cloudflare·3d ago
Cache - Cache multiple versions of a URL with Vary
Cloudflare·3d ago
AI Search - Manage AI Search sync jobs with Wrangler CLI
Cloudflare·3d ago
Cloudflare One - Hostname routing for Cloudflare Mesh
Cloudflare·3d ago

Comments
Sign in to join the conversation.
No comments yet. Be the first.