Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Improve path.resolve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and ry committed Jan 11, 2011
1 parent 320a56b commit 0114826
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions doc/api/path.markdown
Expand Up @@ -29,34 +29,42 @@ Example:

### path.resolve([from ...], to)

Resolves `to` to an absolute path name and normalizes it.
Resolves `to` to an absolute path.

One ore more `from` arguments may be provided to specify the the starting
point from where the path will be resolved. `resolve` will prepend `from`
arguments from right to left until an absolute path is found. If no `from`
arguments are specified, or after prepending them still no absolute path is
found, the current working directory will be prepended eventually.
If `to` isn't already absolute `from` arguments are prepended in right to left
order, until an absolute path is found. If after using all `from` paths still
no absolute path is found, the current working directory is used as well. The
resulting path is normalized, and trailing slashes are removed unless the path
gets resolved to the root directory.

Trailing slashes are removed unless the path gets resolved to the root
directory.
Another way to think of it is as a sequence of `cd` commands in a shell.

Examples:
path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')

path.resolve('index.html')
// returns
'/home/tank/index.html'
Is similar to:

cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd

The difference is that the different paths don't need to exist and may also be
files.

Examples:

path.resolve('/foo/bar', './baz')
// returns
'/foo/baz/baz'
'/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// returns
'/home/tank/wwwroot/static_files/gif/image.gif'
// if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif'

### path.dirname(p)

Expand Down

0 comments on commit 0114826

Please sign in to comment.