Answer the question
In order to leave comments, you need to log in
Why do modules require a variable?
Hello, I am including two modules that fs requires.
const fs = require('fs');
var module1 = require('./module1');
var module2 = require('./module2');
/Users/cyberbober/Desktop/nodejs/2/module1.js:8
fs.readdir(path, (err, files) => {
^
ReferenceError: fs is not defined
at getFiles (/Users/cyberbober/Desktop/nodejs/2/module1.js:8:9)
at Seek (/Users/cyberbober/Desktop/nodejs/2/module1.js:59:1)
at Object.<anonymous> (/Users/cyberbober/Desktop/nodejs/2/module1.js:69:30)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
Answer the question
In order to leave comments, you need to log in
You are missing the fs variable in module1.
The variables here are not global, and in each module you need to separately connect dependencies. Good luck!
fs should probably be connected inside the modules, since you access fs from there.
The node does not have many global variables, these are module, console, process , maybe something else, I don’t remember. All other functions require inclusion in those files, links in which they are maintained. Yes, and in the log it gives you a specific line of a specific file where the error occurred, I think this is obvious.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question