nodejs之路探寻

在webpack配置中经常会发现

const path = require('path')

这是加载nodejs路径处理API,这个API主要包含下面三个方法 

path.dirname(filepath) // 获取文件路径
path.basename(filename) // 获取文件名
path.extname(filepath) // 获取扩展名
path.relative(from, to) // 获取两路径的相对路径

 下面我们可以试验一下

建立一个demo.js文件,键入如下代码

运行并输出

更多path相关API可查看官方文档:http://nodejs.cn/api/path.html

原文地址:https://www.cnblogs.com/Zhangzhiwei-0/p/9546529.html