Mar*_*ahn 4 javascript node.js
“简单”问题——我试图获取节点脚本目录的路径,但是当我从符号链接目录运行时,我不断获取物理文件的路径而不是符号链接结构的路径。如何获得符号链接路径?
/path/to/symlink --> /path/to/real
/path/to/symlink> node echo.js
# echo.js
console.log( __dirname ); // /path/to/real
console.log( process.cwd() ); // /path/to/real
Run Code Online (Sandbox Code Playgroud)
[编辑] 只是为了澄清我自己的理智:
$ mkdir test
$ cd test
test$ mkdir a
test$ ln -s a b
test$ cd b
b$ node
> process.cwd()
'/test/a'
Run Code Online (Sandbox Code Playgroud)