nodejs之path模塊
阿新 • • 發佈:2018-09-22
文件名 www path模塊 clas bsp sdf 解析 div .html
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);
運行效果如下:
nodejs之path模塊