https://github.com/peterdee/node-als-example
An example of the Async Local Storage usage in Node
https://github.com/peterdee/node-als-example
als async-hooks async-local-storage express jest nodejs
Last synced: 3 months ago
JSON representation
An example of the Async Local Storage usage in Node
- Host: GitHub
- URL: https://github.com/peterdee/node-als-example
- Owner: peterdee
- License: mit
- Created: 2021-01-07T13:36:11.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2021-01-07T14:29:52.000Z (over 5 years ago)
- Last Synced: 2026-01-03T15:33:36.023Z (6 months ago)
- Topics: als, async-hooks, async-local-storage, express, jest, nodejs
- Language: JavaScript
- Homepage: http://localhost:2121
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## node-als-example
[](https://travis-ci.com/peterdee/node-als-example)
An example of how the [Async Local Storage (ALS)](https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage) from [`async_hooks`](https://nodejs.org/api/async_hooks.html) can be utilized.
The application is a basic [Express](http://expressjs.com) server that writes data into the ALS in the middleware and then reads data from ALS in the API handler.
### Deploy
```shell script
git clone https://github.com/peterdee/node-als-example
cd ./node-als-example
nvm use 14
npm i
```
### Launch
```shell script
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
```shell script
npm run test
```
### Linting
```shell script
npm run lint
```
### License
[MIT](LICENSE)