https://github.com/hellocomet/hello-cls
A Node.js library that implements Continuation-Local Storage for Node 10+
https://github.com/hellocomet/hello-cls
async-hooks asynchooks cls continuation-local-storage hello-cls node
Last synced: 10 months ago
JSON representation
A Node.js library that implements Continuation-Local Storage for Node 10+
- Host: GitHub
- URL: https://github.com/hellocomet/hello-cls
- Owner: hellocomet
- License: mit
- Created: 2019-06-07T09:43:16.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T18:46:22.000Z (over 3 years ago)
- Last Synced: 2025-07-24T05:28:49.914Z (10 months ago)
- Topics: async-hooks, asynchooks, cls, continuation-local-storage, hello-cls, node
- Language: JavaScript
- Size: 914 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hello-cls
[](https://www.npmjs.com/package/hello-cls)
[](https://github.com/hellocomet/cls/actions)
[](https://codecov.io/gh/hellocomet/hello-cls)
[](https://standardjs.com)
A Node.js library that implements Continuation-Local Storage for Node 10+
## Install & Requirements
`npm i hello-cls`
or
`yarn add hello-cls`
## How to use
```javascript
const { namespace } = require('hello-cls')
const context = namespace.initContext()
// I can't get a value from the namespace if one has not been set yet
console.log(namespace.get('beer'))
// -> undefined
// I can set a value to a given key on the namespace
namespace.set('beer', '🍺')
// I can get a value from the namespace
console.log(namespace.get('beer'))
// -> '🍺'
// close with 'true' will flush state immediately
context.close(true)
// I can't get a value from the namespace if the context is closed
console.log(namespace.get('beer'))
// -> null
```
Made with ❤️ at [**comet**](https://comet.co/)