node path.resolve()
这篇文章发布于 2020/01/10,归类于 前端工程化
标签:
node path.resolve,node路径处理
koa静态文件服务中间件的实现里,需要将当前路径 __dirname 与用户传入的路径合并为一个绝对路径,就可以使用path.resolve函数
The path.resolve() method resolves a sequence of paths or path segments into an absolute path.
const path = require('path')
path.resolve('/foo/bar', './baz');
// Returns: '/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/');
// Returns: '/tmp/file'
let dirPath = './public'
path.resolve(__dirname, dirPath)