When you write a Worker, you may need to import packages from npm â. Many npm packages rely on APIs from the Node.js runtime â, and will not work unless these Node.js APIs are available.
Cloudflare Workers provides a subset of Node.js APIs in two forms:
To enable built-in Node.js APIs and add polyfills, add the nodejs_compat
compatibility flag to your wrangler configuration file, and ensure that your Worker's compatibility date is 2024-09-23 or later. Learn more about the Node.js compatibility flag and v2.
{
"compatibility_flags": [
"nodejs_compat"
],
"compatibility_date": "2024-09-23"
}
compatibility_flags = [ "nodejs_compat" ]
compatibility_date = "2024-09-23"
The runtime APIs from Node.js listed below as "ð¢ supported" are currently natively supported in the Workers Runtime.
Deprecated or experimental APIs from Node.js â, and APIs that do not fit in a serverless context, are not included as part of the list below:
API Name Natively supported by the Workers Runtime Assertion testing ð¢ supported Asynchronous context tracking ð¢ supported Buffer ð¢ supported Console ð¢ supported Crypto ð¢ supported Debugger ð¢ supported via Chrome Dev Tools integration Diagnostics Channel ð¢ supported DNS ð¢ supported Errors ð¢ supported Events ð¢ supported File system ⪠coming soon Globals ð¢ supported HTTP ð¡ partially supported HTTP/2 ⪠not yet supported HTTPS ð¡ partially supported Inspector ð¢ supported via Chrome Dev Tools integration Net ð¢ supported OS ⪠not yet supported Path ð¢ supported Performance hooks ð¡ partially supported Process ð¢ supported Query strings ð¢ supported Stream ð¢ supported String decoder ð¢ supported Timers ð¢ supported TLS/SSL ð¡ partially supported UDP/datagram ⪠not yet supported URL ð¢ supported Utilities ð¢ supported Web Crypto API ð¢ supported Web Streams API ð¢ supported Zlib ð¢ supportedUnless otherwise specified, native implementations of Node.js APIs in Workers are intended to match the implementation in the Current release of Node.js â.
If an API you wish to use is missing and you want to suggest that Workers support it, please add a post or comment in the Node.js APIs discussions category â on GitHub.
Node.js APIs that are not yet supported in the Workers runtime are polyfilled via Wrangler, which uses unenv â. If the nodejs_compat
compatibility flag is enabled, and your Worker's compatibility date is 2024-09-23 or later, Wrangler will automatically inject polyfills into your Worker's code.
Adding polyfills maximizes compatibility with existing npm packages by providing modules with mocked methods. Calling these mocked methods will either noop or will throw an error with a message like:
[unenv] <method name> is not implemented yet!
This allows you to import packages that use these Node.js modules, even if certain methods are not supported.
Enable only AsyncLocalStorageIf you need to enable only the Node.js AsyncLocalStorage
API, you can enable the nodejs_als
compatibility flag:
{
"compatibility_flags": [
"nodejs_als"
]
}
compatibility_flags = [ "nodejs_als" ]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4