Name Last Update
..
browser Loading commit data...
server Loading commit data...
.eslintignore Loading commit data...
.eslintrc Loading commit data...
.npmignore Loading commit data...
CHANGES.md Loading commit data...
CONTRIBUTING.md Loading commit data...
README.md Loading commit data...
package.json Loading commit data...

README.md

loopback-context

Current context for LoopBack applications, based on node-continuation-local-storage.

WARNING

The module node-continuation-local-storage is known to have many problems, see e.g. issue #59. As a result, loopback-context does not work in many situations, as can be seen from issues reported in LoopBack's issue tracker.

We recommend AGAINST using this module.

If you are running on Node v6, you can try the new alternative cls-hooked.

Usage

1) Add per-request middleware to your server/middleware-config.json:

{
  "initial": {
    "loopback-context#per-request": {
    }
  }
}

2) Then you can access the context from your code:

var LoopBackContext = require('loopback-context');

// ...

MyModel.myMethod = function(cb) {
  var ctx = LoopBackContext.getCurrentContext();
  ctx.get('key');
  ctx.set('key', { foo: 'bar' });
});

See the official LoopBack documentation for more details.