Reputation: 1710
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
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