I am having issues including files to execute in my NodeJs project.
I have two files in the same directory:
a.js
var test = "Hello World";
and
b.js
require('./a.js');
console.log(test);
I execute b.js with node b.js and get the error ReferenceError: test is not defined.
I have looked through the docs http://nodejs.org/api/modules.html#modules_file_modules
What am I missing?
Change a.js to export the variable:
and assign the return value of
require('./a.js')to a variable:Another pattern you will often see and probably use is to assign something (an object, function) to the
module.exportsobject in a.js, like so: