Thursday, 14 February 2019

How can I return a value to original module when I call the imported function in another module?

I have two modules: lets call them a and b​module A: I have a function that has the following:var data;var storeData=function (el){data=el;}​console.log(data);module.exports={storeData};​Module B: I import the above from A and call it and pass a param:var test=require("./moduleA")test.storeData("hello");​So now, basically when I call this I want the console.log(data) in module A to spit out "hello". What doesn't this work?​

Submitted February 14, 2019 at 09:17PM by gqtrees

No comments:

Post a Comment