Cheat Sheet速查表
跳转到主要内容

Node.js 路径 API 速查表

本文根据 Devhints / Node.js path API 翻译。代码示例及版本范围沿用原文。

快速参考 Node.js 路径 API.

函数

const fs = require('fs')

fs.realpath('/etc/passwd', function (err, path) {
  path // => "/private/etc/passwd"
})
const path = require('path')
dir = path.join('etc', 'passwd')
dir = path.resolve('/etc', 'passwd', '..', 'var')
path.dirname('/etc/passwd') //      => "/etc"
path.basename('/etc/passwd') //     => "passwd"
path.basename('/etc/rc.d', '.d') // => "rc"

参考资料