Cloudflare 中文文档
Workers
Workers
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

process

The process module in Node.js provides a number of useful APIs related to the current process. Within a serverless environment like Workers, most of these APIs are not relevant or meaningful, but some are useful for cross-runtime compatibility. Within Workers, the following APIs are available:

​​ process.env

In the Node.js implementation of process.env, the env object is a copy of the environment variables at the time the process was started. In the Workers implementation, there is no process-level environment, so env is an empty object. You can still set and get values from env, and those will be globally persistent for all Workers running in the same isolate and context (for example, the same Workers entry point).

​​ Relationship to per-request env argument in fetch() handlers

Workers do have a concept of environment variables that are applied on a per-Worker and per-request basis. These are not accessible automatically via the process.env API. It is possible to manually copy these values into process.env if you need to. Be aware, however, that setting any value on process.env will coerce that value into a string.

It is strongly recommended that you do not replace the entire process.env object with the request env object. Doing so will cause you to lose any environment variables that were set previously and will cause unexpected behavior for other Workers running in the same isolate. Specifically, it would cause inconsistency with the process.env object when accessed via named imports.

​​ process.nextTick()

The Workers implementation of process.nextTick() is a wrapper for the standard Web Platform API queueMicrotask().

Refer to the Node.js documentation for process for more information.