Skip to content
Cloudflare Docs

Changelog

New updates and improvements at Cloudflare. Subscribe to RSS

hero image

Access your Worker's environment variables from process.env

Mar 11, 2025, 03:00 PM

You can now access environment variables and secrets on process.env when using the nodejs_compat compatability 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.

After April 1, 2025, populating process.env will become the default behavior when nodejs_compat is enabled, and your Worker's compatability date is after "2025-04-01". Until then, users can opt-in to this behavior by adding the nodejs_compat_populate_process_env compatability flag.