NodeJs require(‘./file.js’) issues

Change a.js to export the variable:

exports.test = "Hello World";

and assign the return value of require('./a.js') to a variable:

var a = require('./a.js');
console.log(a.test);

Another pattern you will often see and probably use is to assign something (an object, function) to the module.exports object in a.js, like so:

module.exports = { big: "string" };

Leave a Comment