How can I detect whether my Node.JS file was called using SH:node path-to-file or JS:require(\'path-to-file\')?
This is the Node.JS equival
I was a little confused by the terminology used in the explanation(s). So I had to do a couple quick tests.
I found that these produce the same results:
var isCLI = !module.parent;
var isCLI = require.main === module;
And for the other confused people (and to answer the question directly):
var isCLI = require.main === module;
var wasRequired = !isCLI;