Nodejs Module Scope Problems
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?
Voters
No, but you can use
message
as an argument for moduleA.So you would do
moduleA(message);
instead ofmoduleA();
and alsomodule.exports = (message) => {
instead ofmodule.exports = () => {
✅ Please mark this comment as the answer if it helped. Thanks!