Node.js API compatibility - Utils
Explore the integration and usage of the Node.js Util module within the Azion Runtime. The Util module provides a set of utility functions for various data processing tasks, including formatting strings, debugging, and extending objects.
The util module in Node.js provides a set of utility functions that assist with various tasks, enhancing the functionality of JavaScript and Node.js applications. It’s particularly useful for developers looking to simplify common programming tasks and improve code readability. This module is available in the Azion Runtime through Node.js compatibility, where helpers such as promisify and inspect are handy for adapting callback-based code and for logging structured data inside a function.
Example: Promisify and inspect
The example below shows how to use the util module in a function:
Example: Converting callbacks to promises
Use promisify to convert callback-style functions to async/await:
Example: Deep object inspection
Use inspect for detailed object logging and debugging:
Example: Type checking utilities
Use util.types for runtime type checking:
Example: String formatting and deprecation
Use format strings and mark deprecated functions:
Example: Inheritance and class utilities
Use inherits for prototypal inheritance patterns:
Supported APIs
| API | Status |
|---|---|
util.promisify() | 🟢 Supported |
util.inspect() | 🟢 Supported |
util.format() | 🟢 Supported |
util.deprecate() | 🟢 Supported |
util.isDeepStrictEqual() | 🟢 Supported |
util.inherits() | 🟡 Deprecated (use ES6 classes) |
util.callbackify() | 🟡 Partially supported |
util.formatWithOptions() | 🟡 Partially supported |
util.getSystemErrorMap() | 🟡 Partially supported |
util.getSystemErrorName() | 🟡 Partially supported |
util.log() | 🟡 Partially supported |
util.stripVTControlCharacters() | 🟡 Partially supported |
util.styleText() | 🟡 Partially supported |
util.types.isDate() | 🟢 Supported |
util.types.isRegExp() | 🟢 Supported |
util.types.isPromise() | 🟢 Supported |
util.types.isArrayBuffer() | 🟢 Supported |
util.types.isNativeError() | 🟢 Supported |
util.types.isTypedArray() | 🟢 Supported |
util.types.isMap() | 🟢 Supported |
util.types.isSet() | 🟢 Supported |
util.types.isCryptoKey() | 🟢 Supported |
util.types.isKeyObject() | 🟢 Supported |
Note: APIs marked as 🟡 Partially supported have limited functionality compared to the full Node.js implementation. Note that
util.inherits()is deprecated since Node.js v5.0.0 — prefer ES6classsyntax withextendsfor inheritance. For type checking,util.typesprovides runtime-safe alternatives toinstanceofchecks.