0

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();
 }
}
Radu Diță
  • 13,476
  • 2
  • 30
  • 34
Mahmoud Niypoo
  • 1,598
  • 5
  • 24
  • 41

1 Answers1

1

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();
      } 
    }
}
Mahmoud Niypoo
  • 1,598
  • 5
  • 24
  • 41
Radu Diță
  • 13,476
  • 2
  • 30
  • 34