any86 / Notes

:rocket: 笔记
https://github.com/any86/Notes/issues
28 stars 9 forks source link

path.resolve最简单的解释 #23

Open any86 opened 5 years ago

any86 commented 5 years ago

先介绍下的3个路径的含义.

/

根目录

./

当前目录

../

上级目录

path.resolve可以理解为cd命令., 那么官网的例子就好理解了:

path.resolve('/foo/bar', './baz');
// 返回: '/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/');
// 返回: '/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// 如果当前工作目录是 /home/myself/node,
// 则返回 '/home/myself/node/wwwroot/static_files/gif/image.gif'