node path.resolve()和path.join()
发布日期:2021-05-09 05:46:16 浏览次数:18 分类:博客文章

本文共 788 字,大约阅读时间需要 2 分钟。

一:path.resolve

作用:把一个路径或路径片段的序列解析为一个绝对路径。相当于执行cd操作。

let myPath = path.resolve(__dirname,'/img/so');let myPath1=path.resolve('/foo/bar', './baz'); console.log(__dirname); //    E:\test          console.log(myPath);    //    E:\test\img\soconsole.log(myPath1);   //    E:\test\foo/bar\baz

二:path.join

作用:将路径片段使用特定的分隔符(window:\)连接起来形成路径,并规范化生成的路径。若任意一个路径片段类型错误,会报错.

let myPath1 = path.join(__dirname,'/img/so');let myPath2=path.join(__dirname, '/foo', 'bar', 'baz/asdf', 'quux', '..');let myPath3=path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');  console.log(__dirname);  //    E:\test         console.log(myPath1);    //    E:\test\img\soconsole.log(myPath2);    //    E:\test\foo\bar\baz\asdfconsole.log(myPath3);    //    \foo\bar\baz\asdf

顺便给大家推荐一个接口测试软件,十分方便我们前端用户调试接口。可以完美替换postman。

上一篇:apipost 如何分享多个接口
下一篇:完美替代postman的接口测试工具—— apipost

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年04月27日 11时23分24秒