This is the first time I ask a question here. I have the following example case: The export.js file contains a function and some extra lines of code. In this case, it's just a log:
//exporting.js
function add(a,b) {
return a+b;
}
console.log(add(5,8));
module.exports = add;
The import.js file requires the function add, but when it's executed it also prints the log in exporting.js
//import.js
adds = require('./exporting.js');
console.log(adds(1,2));
So it finally prints:
13
3
I want to know if there's a way to require a function without executing all the required file.
I've tried placing my function inside an object, but it still prints the first log.
I hope you can help me, I haven't find anything related, sorry if it's a noob question.