Node.js

path

// node内置模块

返回目录
// node内置模块
// 引入path模块
let path = require("path");
console.log(__dirname); //当前目录
// 合并路径
let filepath = path.resolve(__dirname, "avatar", "defalut.png"); //拼接路径
// D: \Bluej\node\path\avatar\default.png

//先转成对象
let fileObjct = path.parse(filepath);
console.log(fileObjct);

//格式化路径
console.log(path.format(fileObjct));

// 解析文件路径(文件名、后缀名等)
let file = path.parse("F:/bluej/class-23/lesson/index.js");
console.log(file);

// 拼接路径
// join可以写若干多个路径,返回上一层可以写..表示
let indexPath = path.join(__dirname, "..", "index");
console.log(indexPath);