Expanding / Resolving ~ in node.js

前端 未结 7 1727
慢半拍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:00

    An example:

    const os = require("os");

    "~/Dropbox/sample/music".replace("~", os.homedir)

提交回复
热议问题