How can I detect whether my Node.JS file was called using SH:node path-to-file or JS:require(\'path-to-file\')?
node path-to-file
require(\'path-to-file\')
This is the Node.JS equival
There is another, slightly shorter way (not outlined in the mentioned docs).
var runningAsScript = !module.parent;
I outlined more details about how this all works under the hood in this blog post.