Nodejs Module Scope Problems
Vandesm14 (1636)

I have a testing scenario setup which involves a top-level variable and a module. The module consists of a function which is supposed to log said variable to the console. But I cannot seem to get the variable message to work with moduleA.

Is there a way to use main variables/functions inside another module?

You are viewing a single comment. View All
mat1 (2866)

No, but you can use message as an argument for moduleA.
So you would do moduleA(message); instead of moduleA(); and also module.exports = (message) => { instead of module.exports = () => {

✅ Please mark this comment as the answer if it helped. Thanks!