path.join vs path.resolve in node.js


  • path.join([...paths])
    • joins all the path seg­ments using plat­form spe­cific delimiter.
path.join('/foo', 'bar', 'baz/zxcv', 'abcd', '..') // '/foo/bar/baz/zxcv/abcd/...'

  • path.resolve([...paths])
    • Resolves all the path seg­ments into an absolute path.
    • It processes from right to left, until an absolute path is created.
    • If after pro­cess­ing all given path seg­ments an absolute path has not yet been gen­er­ated, the cur­rent work­ing direc­tory is used.
path.resolve('/foo/bar', '/temp/file/') // '/temp/file'

path.resolve('www', 'static/png/', '../gif/image.gif') // '/home_dir/www/static/gif/image.gif'

  • (path.resolve)[https://nodejs.org/api/path.html#path_path_resolve_paths]
  • (path.join)[https://nodejs.org/api/path.html#path_path_join_paths]

You may also like...