---
source: https://iinventedlight.com/library/notes/node-async-local-storage.md
title: "AsyncLocalStorage keeps a store coherent across async operations"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs); MIT (nodejs/node (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Node.js, Asynchronous context tracking, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors; nodejs/node (GitHub), async_context.md (Node.js source docs), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Node.js AsyncLocalStorage"
tags: [nodejs, AsyncLocalStorage, async_hooks, getStore, request-context]
client: Librarian
sources:
  - id: S1
    title: "Asynchronous context tracking"
    publisher: Node.js
    url: https://nodejs.org/api/async_context.html
    accessed: 2026-11-17
    license: "MIT"
  - id: S2
    title: "async_context.md (Node.js source docs)"
    publisher: nodejs/node (GitHub)
    url: https://github.com/nodejs/node/blob/main/doc/api/async_context.md
    accessed: 2026-11-17
    license: "MIT"
---
# AsyncLocalStorage keeps a store coherent across async operations
**Answer:** `AsyncLocalStorage` creates stores that stay coherent through asynchronous operations. Import it from `node:async_hooks`. `run` runs a function synchronously within a context and returns its return value. The store is accessible to any asynchronous operations created within the callback. `getStore()` returns the current store.

## run and getStore

`run` executes a function synchronously in the context and returns its return value. The store is not visible outside that callback, but it is visible to asynchronous operations created inside the callback. If the callback throws, `run` throws too.

`getStore()` returns the current store. Outside a context started with `run()` or `enterWith()`, it returns `undefined`. Each `AsyncLocalStorage` instance keeps an independent storage context.

## Prefer run over enterWith

`enterWith(store)` moves into the context for the rest of the current synchronous execution, then keeps the store for asynchronous calls that follow. Subsequent event handlers also run within that context when it is entered within an event handler. Prefer `run()` over `enterWith()` unless you have strong reasons to use the latter method.

## See also

- [node-events](https://iinventedlight.com/library/notes/node-events/)
- [node-http-and-url](https://iinventedlight.com/library/notes/node-http-and-url/)
- [node-child-process](https://iinventedlight.com/library/notes/node-child-process/)
- [node-buffer](https://iinventedlight.com/library/notes/node-buffer/)

## Claims

- id: C1
  claim: AsyncLocalStorage stores stay coherent through asynchronous operations.
  source: S1
  evidence: "stores that stay coherent through asynchronous operations"

- id: C2
  claim: getStore returns undefined outside a run or enterWith context.
  source: S1
  evidence: "it returns undefined"

- id: C3
  claim: run runs a function in a context and returns its return value.
  source: S2
  evidence: "Runs a function synchronously within a context and returns its"

- id: C4
  claim: run should be preferred over enterWith in ordinary use.
  source: S2
  evidence: "`run()` should be preferred over `enterWith()`"

## Sources

- [S1] Asynchronous context tracking. Node.js. https://nodejs.org/api/async_context.html . License: MIT. Accessed 2026-11-17.

- [S2] async_context.md (Node.js source docs). nodejs/node (GitHub). https://github.com/nodejs/node/blob/main/doc/api/async_context.md . License: MIT. Accessed 2026-11-17.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js, Asynchronous context tracking, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors; nodejs/node (GitHub), async_context.md (Node.js source docs), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
