npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

moleculer-cls

1.0.0 • Public • Published

Hooked Continuation-Local Storage for Moleculer

Add support for continuation local storage in moleculer action handlers.

Current Version (v1.0.0)

Install

npm install --save moleculer-cls

Usage

// moleculer.config.js
 
const context = require('moleculer-cls');
 
module.exports = {
  ...
  middlewares: [
    context.middleware
  ]
}
// service.js
 
const context = require('moleculer-cls');
const process = require('processor.js');
 
module.exports = {
  actions: {
    hello: {
      params: {
        properties: {
          "name": {type: "string"}
        },
        required: ["name"]
      },
      handler: async (ctx) => {
        context.set('request_id', ctx.requestID);
        
        return await process(ctx.params);
      }
    }
  }
}
// processor.js
 
const context = require('moleculer-cls');
 
module.exports = async ({name}) => {
  console.log(`Processing ${context.get('request_id')}`);
 
  return Promise.resolve(`Hello ${name}`);
}

License

MIT

install

npm i moleculer-cls

Downloadsweekly downloads

2

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability