nodejs之path模块
path路径模块的使用
1、basename返回文件名
let path = require('path'); let str = path.basename('/foo/bar/baz/asdf/test.html', '.html'); console.log(str);
运行
2、join将所有的路径段连接成完整路径
let path = require('path'); let str = path.basename('/foo/bar/baz/asdf/test.html', '.html'); console.log(str); let pth = path.join('/foo','bar','baz/asdf','test'); console.log(pth);
运行:
3、resolve将一系列的路径段解析成绝对路径
let path = require('path'); let abspath = path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif'); console.log(abspath);
运行效果如下: