node.js

process.cwd()方法

作用:返回进程的当前目录(绝对路径)

path.resolve([...paths])

  • ...paths:路径序列或路径片段
  • Returns
    该方法将传入的路径序列或路径片段解析到绝对路径中,可以理解为将传入的地址与当前进程的路径拼接为一个绝对路径
    注意: 它是从右到左进行处理的,直到形成一个绝对路径

例如:

path.resolve('/foo/bar', './baz');
// retures: '/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/');
// returns: '/tmp/file/' 
它是从右向左进行解析的,一旦形成绝对路径就返回,因此返回'/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// 假设当前路径为 '/home/src'
// returns: '/home/src/wwwroot/static_files/gif/image.gif'
// 注意" ../gif" 找到"/home/src/wwwroot/static_files/png"的上一级目录,因此是'/home/src/wwwroot/static_files/'

fs.readdirSync(path[, options])

  • path | |
  • returns:返回一个数组,该数组包含的是path路径下的所有文件和文件夹的名字
    如:
node.js_第1张图片
image.png

你可能感兴趣的:(node.js)