开发者

How can one find the name with which a Node.js CLI script was called?

开发者 https://www.devze.com 2023-02-08 10:20 出处:网络
I have a script that should behave differently depending on what it is called as (think vimdiff). __filename is specifically designed to give the real name of the file, following aliases and symlinks

I have a script that should behave differently depending on what it is called as (think vimdiff). __filename is specifically designed to give the real name of the file, following aliases and symlinks and such. Is there a way to get the original开发者_高级运维 command name?

So that if I call:

node_script --foo=bar

Or:

scriptForNode --foo=bar

And they both reference the same code, how can I get the node_script or scriptForNode part out?

(Ideally, it should deal with aliases, bash functions, and symlinks equally well, but I'll take what I can get.)


How about process.argv[0]?

(Or perhaps that should be process.argv[1], since [0] would probably return node).

0

精彩评论

暂无评论...
验证码 换一张
取 消