Is it possible to to have this return an output ?
hello.js
var y = 1;
console.log(x);
console.log(y);
main.js
var x = 42;
var magic = somehowInclude('hello.js');
And when you run main.js
with node it prints 42
and 1
Is it to possible to do this without require
and exports
?
Use Node.js modules.
hello.js
module.exports.magic = function (x) {
var y = 1;
console.log(x);
console.log(y);
};
main.js
var x = 42;
var hello = require('./hello.js');
hello.magic(42);
Read the detailed description of the module loading system at in the Node.js documentation.