Skip to content

peterdee/node-als-example

Repository files navigation

node-als-example

Build Status

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.

Deploy

git clone https://github.com/peterdee/node-als-example
cd ./node-als-example
nvm use 14
npm i

Launch

npm start

The app will be launched at http://localhost:2121, a different port can be specified with the PORT environment variable.

APIs

  • / - [GET] - get a response with a unique identifier
  • /delayed - [GET] - get delayed response (accessing ALS inside the setTimeout)

Tests

npm run test

Linting

npm run lint

License

MIT