how to detect js module was required

49

how to detect js module was required -

if (require.main === module) {
    console.log('called directly');
} else {
    console.log('required as a module');
}

Comments

Submit
0 Comments