How do I know if a node script is running directly or included?
I have a node.js file:
#!/usr/bin/env node
module.exports = 'foo';
I am trying to add at the bottom:
if(is run as shell script){
console.log(module.exports);
}
Is there a correct way to do this? I can hack something using things like process.argv
and __filename
, but is this the best way?
+3
Mark kahn
source
to share
No one has answered this question yet
See similar questions:
253
or similar:
868
867
861
499
340
274
61
fourteen
4
0