You can use module.parent to determine if the current script is loaded by another script.
e.g.
a.js:
if (!module.parent) {
console.log("I'm parent");
} else {
console.log("I'm child");
}
b.js:
require('./a')
run node a.js will output:
I'm parent
run node b.js will output:
I'm child