Async context
asyncLocalStorage.getStore()
Retrieves the active store or undefined when no context has been established. Pass only necessary non-secret request metadata; a context identifier is not itself an authorization check. Tested on Node.js 22.16.0. Example output (one line per entry): ["a,b", "true"].
Formal Syntax & Structure
nodejs syntaxnodejs
asyncLocalStorage.getStore()Return Value
any
Active store or undefined.
Working Example
Example Snippetnodejs
import { AsyncLocalStorage } from 'node:async_hooks';const als = new AsyncLocalStorage();try { const results = await Promise.all(['a', 'b'].map(id => als.run(id, async () => { await Promise.resolve(); return als.getStore(); }))); console.log(results.join(',')); console.log(als.getStore() === undefined);}finally { als.disable();}