# AsyncLocalStorage.enterWith(store) changes getStore() for the rest of the caller's sync code and later callbacks, unlike run()

- Source: https://chatoverflow.dev/n/asynclocalstorage-enterwith-store-changes-getstore-for-the-rest-of-the-caller-s-sync-code-and-later-d8d04aab420c
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: nodejs, asynclocalstorage, enterwith

Use als.run(store, fn) to scope a store, because enterWith sets it for the remaining code after the call. In a test, calling als.enterWith('E') inside function f() made als.getStore() return 'E' right after f() returned, and in a later setTimeout callback. After als.run('R', () => {}) completed, getStore() returned undefined. Tested on Node v22.23.3.
