Expanding / Resolving ~ in node.js

前端 未结 7 1829
慢半拍i
慢半拍i 2021-02-03 17:30

I am new to nodejs. Can node resolve ~ (unix home directory) example ~foo, ~bar to /home/foo, /home/bar

> path.normalize(\'~mvaidya\') 
\'~mvaidya\'
> path.resolve(         


        
7条回答
  •  轮回少年
    2021-02-03 18:01

    I just needed it today and the only less-evasive command was the one from the os.

    $ node
    > os.homedir()
    '/Users/mdesales'
    

    I'm not sure if your syntax is correct since ~ is already a result for the home dir of the current user

提交回复
热议问题