NestJS · Middle · Question 57 of 75
How can you read the current request ID in deep services without passing it through every call?
- 1Make every service request-scoped
- ✓Correct answer: With
AsyncLocalStorage(e.g. thenestjs-clspackage), set in middleware at the start of each request - 3Store it in a global variable
Explanation
ALS follows the async context of the request without the performance cost of request-scoped providers.