path.join vs path.resolve in node.js

  • path.join([...paths])
    • joins all the path segments using platform specific delimiter.
path.join('/foo', 'bar', 'baz/zxcv', 'abcd', '..') // '/foo/bar/baz/zxcv/abcd/...'

  • path.resolve([...paths])
    • Resolves all the path segments into an absolute path.
    • It processes from right to left, until an absolute path is created.
    • If after processing all given path segments an absolute path has not yet been generated, the current working directory 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)[]
  • (path.join)[]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *