dead simple continuation local storage using async hooks
Last updated 3 years ago by goto-bus-stop .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install async-cls 
SYNC missed versions from official npm registry.


dead simple "continuation-local storage" with Node async_hooks

npm travis standard


npm install async-cls


continuation local storage allows you to implicitly make values available to an asynchronous chain of code. Multiple asynchronous chains of the same code can be running simultaneously, and each will only get access to its own value.

var cls = require('async-cls')
var express = require('express')

var userContext = cls()

var app = express()
app.get('/', function (req, res) {
  userContext.current = req.user
  // you can do any async operation, like filesystem access or waiting for Promises
  // to resolve
  setTimeout(function () {

function respond (res) {
  // `userContext.current` will return the `req.user` value that was set in this async call stack
  res.json({ userId: })


context = cls()

Create a new context. A context can hold a single JavaScript value per async context.

context.current = value

Set the value for this async context (call stack).


Get the value for this async context.


Destroy the context, removing its async_hook and cleaning up any context values. Accessing context.current after the context has been destroyed will return undefined.



Current Tags

  • 1.0.1                                ...           latest (3 years ago)

2 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (0)

Copyright 2014 - 2016 © |