node:async_hooks provides AsyncLocalStorage, AsyncResource, and createHook; import them from
"node:async_hooks".
import { AsyncLocalStorage } from "node:async_hooks";
const storage = new AsyncLocalStorage();
storage.run("request", async () => {
await null;
console.log(storage.getStore()); // request
queueMicrotask(() => console.log(storage.getStore())); // undefined
});Differences from Node
AsyncLocalStoragecontext is lost inqueueMicrotaskcallbacks andnode:fscallbacks.createHookcallbacks (init,before,after,destroy) fire for timers, immediates, and Promise continuations.