Hello,
I'm wondering if I use for e.g. module.exports = new A(); in the file A.js and that A.js will not be used by any other file with require(...) it will be cached to Node.js (if it's started with node A.js)? Because as I tested if I require that A.js in files like B.js and C.js it will be executed only 1 time (in the file who firstly required it), so it means after exporting it, it was executed and cached?
- If
A.js will be executed with node A.js and no one required it, it will be cached to Node.js?
- If
A.js will be used in B.js and C.js with require(...) it will be executed in the file who firstly required it and it will be cached? I mean no matter how much files require A.js it will be executed only 1 time in for e.g. B.js who was first?
A.js
const chalk = require('chalk');
class A {
constructor() {
console.log(chalk.red('Colored msg.'));
}
}
module.exports = new A();
Hello,
I'm wondering if I use for e.g.
module.exports = new A();in the fileA.jsand thatA.jswill not be used by any other file withrequire(...)it will be cached to Node.js (if it's started withnode A.js)? Because as I tested if I require thatA.jsin files likeB.jsandC.jsit will be executed only 1 time (in the file who firstly required it), so it means after exporting it, it was executed and cached?A.jswill be executed withnode A.jsand no one required it, it will be cached to Node.js?A.jswill be used inB.jsandC.jswithrequire(...)it will be executed in the file who firstly required it and it will be cached? I mean no matter how much files requireA.jsit will be executed only 1 time in for e.g.B.jswho was first?A.js