# Node.js APIs

Azion Runtime is compatible with a part of the Node.js APIs, not with all of them. A function, and every npm package it depends on, can import the 68 Node.js modules in the table below. Each one resolves when the build bundles the function, and loads in a deployed function and under `azion dev`. The status of a module says how much of its API works when the function calls it.

> **Note**
>
> Under `azion dev`, some modules behave differently from a deployed function. `node:fs` paths resolve under the `.edge/storage/` folder of the project, an import of `pipeline` from `node:stream` fails the build, and `timingSafeEqual()` and `generateKeyPairSync()` from `node:crypto` throw.

---

## Module imports

A function imports a Node.js module with the standard `import` syntax and the `node:` prefix:

```javascript
import { AsyncLocalStorage } from "node:async_hooks";
import os from "node:os";
```

A polyfill is code that adds a feature to an environment that lacks it. The build resolves through polyfills the Node.js APIs that the runtime does not provide, and the `polyfills` setting of [azion.config.js](/en/documentation/devtools/cli/azion-config-js/) sets whether the build adds them. The list of APIs the build resolves through polyfills is in the [`@aziontech/unenv-preset` package](https://github.com/aziontech/lib/blob/main/packages/unenv-preset/src/index.ts), which also accepts contributions.

---

## Module support

The table lists each module with its status. Where a module page exists, the module name links to it. The Notes column states what a function receives when it calls the module, where that behavior is known.

- 🟢 **Supported**: the API works normally at runtime.
- 🟡 **Partially supported**: only some methods or features are available.
- 🔴 **Build-only**: the module is included so the build completes without errors, but its API calls do not work at runtime.

> **About the Azion Cells runtime environment**
>
> A function on Azion runs inside a **Cell**, the isolation environment Azion builds on **V8 isolates**. A Cell is a lightweight, secure execution context, and the code inside it has no direct access to the operating system underneath.
>
> For multi-tenant security and infrastructure integrity, a Cell does not give a function:
>
> - The properties of the machine that runs it. `node:os` and `process` return fixed values instead, such as `linux` for `os.platform()`, an empty string for `os.hostname()`, and `0` for `os.totalmem()`.
> - DNS resolution through native system calls (`node:dns`, `node:dns/promises`).
> - Low-level TCP or UDP sockets that require direct system calls.
>
> The modules marked 🔴 **Build-only** are included as stubs, so that npm packages with static imports of them still build. Their calls do not work at runtime: `dns.lookup()` throws `Error: [unenv] dns.lookup is not implemented yet!`.

| Module                                                                     | Status                 | Notes                                                                                                                                                                                                                                                                                                                            |
| -------------------------------------------------------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_http\_agent                                                              | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_http\_client                                                             | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_http\_common                                                             | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_http\_incoming                                                           | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_http\_outgoing                                                           | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_http\_server                                                             | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_duplex                                                           | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_passthrough                                                      | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_readable                                                         | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_transform                                                        | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_wrap                                                             | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_stream\_writable                                                         | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_tls\_common                                                              | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| \_tls\_wrap                                                                | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| assert                                                                     | 🟡 Partially supported | `assert.strictEqual(1, 2)` throws an `AssertionError`.                                                                                                                                                                                                                                                                           |
| assert/strict                                                              | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [async\_hooks](/en/documentation/devtools/runtime/node/async-hooks/)       | 🟡 Partially supported | Only [AsyncLocalStorage](https://nodejs.org/api/async_context.html#class-asynclocalstorage) and [AsyncResource](https://nodejs.org/api/async_hooks.html#class-asyncresource) are implemented, and both work. [Code sample](https://github.com/aziontech/azion-samples/tree/dev/samples/node-async-hooks).                        |
| [buffer](/en/documentation/devtools/runtime/node/buffer/)                  | 🟡 Partially supported | `Buffer` is also a global. The module-level functions, such as `buffer.isAscii()`, are not supported.                                                                                                                                                                                                                            |
| child\_process                                                             | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| cluster                                                                    | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| console                                                                    | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| constants                                                                  | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [crypto](/en/documentation/devtools/runtime/node/crypto/)                  | 🟡 Partially supported | `createHash()`, `createHmac()`, `randomBytes()`, `randomUUID()`, and `subtle` work.                                                                                                                                                                                                                                              |
| dgram                                                                      | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| diagnostics\_channel                                                       | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| dns                                                                        | 🔴 Build-only          | `dns.lookup()` throws `Error: [unenv] dns.lookup is not implemented yet!`.                                                                                                                                                                                                                                                       |
| dns/promises                                                               | 🔴 Build-only          | —                                                                                                                                                                                                                                                                                                                                |
| domain                                                                     | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [events](/en/documentation/devtools/runtime/node/events/)                  | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [fs](/en/documentation/devtools/runtime/node/fs/)                          | 🟡 Partially supported | A function cannot write files: `fs.writeFileSync()` throws `Error: unsupported`. Synchronous reads use the in-memory file system that the `build.memoryFS` setting fills. On a path the build did not embed, `fs.readFileSync()` throws `ENOENT`, and the callback `fs.readFile()` receives `Error: missing storage annotation`. |
| fs/promises                                                                | 🟡 Partially supported | On a path the build did not embed, `readFile()`, `writeFile()`, `readdir()`, and `stat()` reject with `Error: missing storage annotation`.                                                                                                                                                                                       |
| [http](/en/documentation/devtools/runtime/node/http/)                      | 🟡 Partially supported | `http.STATUS_CODES` and `http.METHODS` are readable. `http.request()`, `http.get()`, and `http.createServer()` throw `[unenv] … is not implemented yet!`.                                                                                                                                                                        |
| http2                                                                      | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| https                                                                      | 🟡 Partially supported | `https.get()` throws `Error: [unenv] https.get is not implemented yet!`.                                                                                                                                                                                                                                                         |
| inspector                                                                  | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| inspector/promises                                                         | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [module](/en/documentation/devtools/runtime/node/module/)                  | 🟡 Partially supported | Behaves the same in a deployed function and under `azion dev`. `module.builtinModules` lists 65 names, and `module.createRequire()` returns `undefined`.                                                                                                                                                                         |
| net                                                                        | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [os](/en/documentation/devtools/runtime/node/os/)                          | 🟡 Partially supported | Every member returns without throwing, with fixed values that do not describe the machine: `os.platform()` returns `linux`, `os.type()` returns `Linux`, and `os.hostname()` returns an empty string.                                                                                                                            |
| [path](/en/documentation/devtools/runtime/node/path/)                      | 🟢 Supported           | Every function operates on path strings, without file system access.                                                                                                                                                                                                                                                             |
| path/posix                                                                 | 🟢 Supported           | `path.posix.join()` returns the same paths as `path.join()`.                                                                                                                                                                                                                                                                     |
| path/win32                                                                 | 🟡 Partially supported | Joins segments with `/`: `path.win32.join("C:\\a", "b")` returns `C:/a/b`.                                                                                                                                                                                                                                                       |
| perf\_hooks                                                                | 🟢 Supported           | `performance.now()` is a function.                                                                                                                                                                                                                                                                                               |
| [process](/en/documentation/devtools/runtime/node/process/)                | 🟡 Partially supported | `process.env` holds the environment variables of your account: read one as `process.env.VAR_NAME`. `process.platform` and `process.arch` are empty strings, and `process.pid` is `200`.                                                                                                                                          |
| punycode                                                                   | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| querystring                                                                | 🟡 Partially supported | `querystring.stringify({ a: [1, 2], b: 'x y' })` returns `a=1&a=2&b=x%20y`.                                                                                                                                                                                                                                                      |
| readline                                                                   | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| readline/promises                                                          | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| repl                                                                       | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [stream](/en/documentation/devtools/runtime/node/stream/)                  | 🟡 Partially supported | `Readable`, `Writable`, `Duplex`, `Transform`, `PassThrough`, and the callback form of `pipeline()` work.                                                                                                                                                                                                                        |
| stream/consumers                                                           | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| stream/promises                                                            | 🟡 Partially supported | `pipeline()` throws `Error: [unenv] stream.promises.pipeline is not implemented yet!`.                                                                                                                                                                                                                                           |
| stream/web                                                                 | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [string\_decoder](/en/documentation/devtools/runtime/node/string-decoder/) | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| sys                                                                        | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [timers](/en/documentation/devtools/runtime/node/timers/)                  | 🟡 Partially supported | A timer callback must be a function: a string or a number in its place throws `EvalError: eval not allowed on setTimeout/setInterval parameter`.                                                                                                                                                                                 |
| timers/promises                                                            | 🟡 Partially supported | The async iterator that `setInterval()` returns yields one value and then ends.                                                                                                                                                                                                                                                  |
| tls                                                                        | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| trace\_events                                                              | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| tty                                                                        | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [url](/en/documentation/devtools/runtime/node/url/)                        | 🟡 Partially supported | `URL` and `URLSearchParams` are globals. `url.parse()`, `url.format()`, `url.resolve()`, `url.fileURLToPath()`, `url.pathToFileURL()`, and `url.domainToASCII()` work.                                                                                                                                                           |
| [util](/en/documentation/devtools/runtime/node/utils/)                     | 🟡 Partially supported | `util.promisify()`, `util.inspect()`, and `util.format()` work.                                                                                                                                                                                                                                                                  |
| util/types                                                                 | 🟡 Partially supported | `util.types.isNativeError()` throws `Error: [unenv] util.types.isNativeError is not implemented yet!`.                                                                                                                                                                                                                           |
| v8                                                                         | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| [vm](/en/documentation/devtools/runtime/node/vm/)                          | 🟡 Partially supported | No method runs code: `runInThisContext()`, `runInNewContext()`, `runInContext()`, and `Script.runInThisContext()` throw `[unenv] … is not implemented yet!`.                                                                                                                                                                     |
| wasi                                                                       | 🟢 Supported           | —                                                                                                                                                                                                                                                                                                                                |
| worker\_threads                                                            | 🟡 Partially supported | —                                                                                                                                                                                                                                                                                                                                |
| [zlib](/en/documentation/devtools/runtime/node/zlib/)                      | 🟡 Partially supported | `zlib.constants` is available, but no function compresses data: `zlib.gzipSync()` throws `Error: [unenv] zlib.gzipSync is not implemented yet!`. To compress data, use the Web `CompressionStream` API.                                                                                                                          |

---

## Related resources

- [Web APIs](/en/documentation/devtools/runtime/api-reference/javascript.md): The Web APIs a function can call, such as fetch and the stream APIs.
- [Frameworks compatibility](/en/documentation/devtools/runtime/frameworks/frameworks-compatibility.md): The web frameworks that build and run on Azion Runtime.
- [Use Node.js APIs through polyfills](/en/documentation/guides/application-development/functions-and-runtime/use-polyfills.md): How the build resolves Node.js APIs through polyfills, shown in a JavaScript project.
- [Globals](/en/documentation/devtools/runtime/api-reference/azion-runtime-globals.md): The global objects of Azion Runtime, which a function uses without an import.
