In my module I need to detect when it's being called from either the command line, or from another module.
const isFromCLI = '????' I'm using Babel/ES6, so when called from a command line, index.js is called (with the babel code), which hands off to script.js (with ES6 code). So from the script file, module.parent returns module (the index.js file). So I can't use module.parent!
Also, module.main is undefined (in script.js) when called from either the command line or from another module. So I can't use module.main!
Those are the two solutions that others are suggesting, but they don't work for me.
Is there a simple to detect this when using Babel/ES6..?
Update
require.main returns module when called from either the command line or from another module.
index.jsis called from the command line which hands off toscript.js, thenscript.jsis not called directly from the command line? Seems fine to me.script.jsis not called directly from the command line. Howeverindex.jsonly contains the Babel code required forscript.jsto work. I see what you're saying though. I thought there might be a different way to detect this, rather than seeing ifmodule.parentis equal tomodule.