An example of how the Async Local Storage (ALS) from async_hooks
can be utilized.
The application is a basic Express server that writes data into the ALS in the middleware and then reads data from ALS in the API handler.
git clone https://github.com/peterdee/node-als-example
cd ./node-als-example
nvm use 14
npm i
npm start
The app will be launched at http://localhost:2121, a different port can be specified with the PORT
environment variable.
/
-[GET]
- get a response with a unique identifier/delayed
-[GET]
- get delayed response (accessing ALS inside thesetTimeout
)
npm run test
npm run lint