Node.js APIs
The Node.js modules a function can import in Azion Runtime, the support status of each one, and what their calls return or throw.
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.
Module imports
A function imports a Node.js module with the standard import syntax and the node: prefix:
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 sets whether the build adds them. The list of APIs the build resolves through polyfills is in the @aziontech/unenv-preset package, 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.
| 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 | 🟡 Partially supported | Only AsyncLocalStorage and AsyncResource are implemented, and both work. Code sample. |
| 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 | 🟡 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 | 🟢 Supported | — |
| 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 | 🟡 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 | 🟡 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 | 🟡 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 | 🟢 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 | 🟡 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 | 🟡 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 | 🟢 Supported | — |
| sys | 🟡 Partially supported | — |
| 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 | 🟡 Partially supported | URL and URLSearchParams are globals. url.parse(), url.format(), url.resolve(), url.fileURLToPath(), url.pathToFileURL(), and url.domainToASCII() work. |
| util | 🟡 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 | 🟡 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 | 🟡 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. |