BMiner BMiner - 1 year ago 215
Node.js Question

Difference between path.normalize and path.resolve in Node.js

What is the difference (if any) between


I know
can accept multiple arguments, but is the behavior with a single argument the same as calling

EDIT: If they are supposed to behave the same way, I don't understand the purpose of exposing the
function when you can simply pass the path into
Or, maybe, it's for documentation purposes. For example, they say in the documentation for

... The resulting path is normalized, and ...

Exposing the
makes it easier to explain what "normalized" means??? I dunno.

Answer Source

path.normalize Gets rid of the extra ., .., etc. in the path. path.resolve resolves a path into an absolute path. Example (my current working directory was /Users/mtilley/src/testing):

> path.normalize('../../src/../src/node')
> path.resolve('../../src/../src/node')

In other words, path.normalize is "What is the shortest path I can take that will take me to the same place as the input", while path.resolve is "What is my destination if I take this path."

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download