node.js - Difference between path.resolve and path.join invocation? -
is there difference between following invocations?
path.join(__dirname, 'app') vs.
path.resolve(__dirname, 'app') which 1 should preferred?
⚠️ pointed out in comments, answer incorrect. see neonpaul's answer below or this answer similar question. sorry not noticing earlier.
path.join() pretty concatenates arguments pass (using right delimiter, forward slash), whereas path.resolve() returns path if navigated directories in sequence (and resolving actual location of file/directory).
for example:
path.join("a", "b1", "..", "b2") === "a/b1/../b2" but
path.resolve("a", "b1", "..", "b2") === "a/b2" in cases, these 2 functions return same value. i'm not aware of performance differences, though reckon path.join bit faster.
Comments
Post a Comment