flâneur — a map of the web's best reading

Asynchronous context tracking | Node.js v26.4.0 Documentation

nodejs.org · 5,240 words · saved by 1 readers

These classes are used to associate state and propagate it throughout callbacks and promise chains. They allow storing data throughout the lifetime of a web request or any other asynchronous duration. It is similar to thread-local storage in other languages. The AsyncLocalStorage and AsyncResource classes are part of the node:async_hooks module: This class creates stores that stay coherent through asynchronous operations. While you can create your own implementation on top of the node:async_hooks module, AsyncLocalStorage should be preferred as it is a performant and memory safe implementation that involves significant optimizations that are non-obvious to implement. The following example uses AsyncLocalStorage to build a simple logger that assigns IDs to incoming HTTP requests and includes them in messages logged within each request. Each instance of AsyncLocalStorage maintains an independent storage context. Multiple instances can safely exist simultaneously without risk of interferi

Asynchronous context tracking | Node.js v26.5.0 Documentation Skip to content Node.js About this documentation Usage and example Assertion testing Asynchronous context tracking Async hooks Buffer C++ addons C/C++ addons with Node-API C++ embedder API Child processes Cluster Command-line options Console Crypto Debugger Deprecated APIs Diagnostics Channel DNS Domain Environment Variables Errors Events File system FFI Globals HTTP HTTP/2 HTTPS Inspector Internationalization Iterable Streams API Modules: CommonJS modules Modules: ECMAScript modules Modules: node:module API Modules: Packages Module

Explore this link on the map →

related reading