Mahmoud Niypoo
Mahmoud Niypoo

Reputation: 1710

pass init value in npm package

Now I'm trying to write a first npm package but I have issue/question, How can I pass value when developer required my package like that

const package = require('my-package')('hello A')

this is code for explain my idea

module.exports=(valueA){
 function : (ValueB)=>{
    console.log(valueA,ValueB)
 },
 middleware : (req,res,next)=>{
    console.log(req,valueA)
    return next();
 }
}

Upvotes: 0

Views: 61

Answers (1)

Radu Diță
Radu Diță

Reputation: 14171

Try this

module.exports=function (valueA) { 
     return {
      someMethod : function (ValueB) {
      console.log(valueA,ValueB)
      },
      middleware : function (req,res,next) {
       console.log(req,valueA)
       return next();
      } 
    }
}

Upvotes: 1

Related Questions