path.join()和path.resolve()的区别
path.join() path.join():方法使用平台特定的分隔符[Unix系统是/,Windows系统是\ ]把全部给定的 path 片段连接到一起,并规范化生成的路径。若任意一个路径片段类型错误,会报错。 例如: __dirname // __dirname返回当前文件所在的绝对路径 const path = require('path'); const path1 = path.join(__dirname, '/foo'); const path2 = path.join(__dirname, './foo/bar'); const path3 = path.join('/foo', 'bar', '/baz/apple', 'aaa', '..'); const path4 = path.join('foo', 'bar', 'baz'); console.log(path1); console.log(path2); console.log(path3); console.log(path4); // 输出结果 /Users/xiao/work/test/foo /Users/xiao/work/test/foo/bar /foo/bar/baz/apple foo/bar/baz 复制代码 不合法的字符串将抛出异常 const path5 = path.join('foo', {}, 'bar'); // TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.
https://juejin.cn/post/6844903861920989198