dev-zuo 技术日常
Github

node path.resolve()

这篇文章发布于 2020/01/10,归类于
标签:
node path.resolvenode路径处理

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)

参考:node path.resolve