Skip to main content
Journey Uncommon Logo
JourneyUncommon
easyNodeJSrequire and module.exportsSingle-choice MCQ

A small library file is run two ways: directly with `node tool.js`, and also imported by another file with `require('./tool')`. How can the file detect that it is being run directly versus being required?

// tool.js if (/* ??? */) { console.log('run directly'); }