AsyncLocalStorage
A Node.js class that keeps a value, such as the current request's ID, available to every function called during one asynchronous operation, without passing it as an argument.
In more detail
als.run(store, fn) makes store visible through als.getStore() inside fn and in every callback, timer and promise continuation it causes. Concurrent requests each see only their own store, so it is the usual base for request-scoped logging and tracing.
Related terms
- async context propagation — Carrying information about the current task, such as which request it serves, across every asynchronous step it takes.
- async_hooks — The Node.js module that tracks the creation and completion of asynchronous resources; its low-level createHook() API is discouraged in favour of AsyncLocalStorage.
- correlation ID — A unique value attached to one request and passed along everywhere it goes, so its logs and traces can be found together.
Taught in
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services