{ "source": "doc/api/path.markdown", "modules": [ { "textRaw": "Path", "name": "path", "stability": 3, "stabilityText": "Stable", "desc": "

This module contains utilities for handling and transforming file\npaths. Almost all these methods perform only string transformations.\nThe file system is not consulted to check whether paths are valid.\n\n

\n

Use require('path') to use this module. The following methods are provided:\n\n

\n", "methods": [ { "textRaw": "path.normalize(p)", "type": "method", "name": "normalize", "desc": "

Normalize a string path, taking care of '..' and '.' parts.\n\n

\n

When multiple slashes are found, they're replaced by a single one;\nwhen the path contains a trailing slash, it is preserved.\nOn Windows backslashes are used.\n\n

\n

Example:\n\n

\n
path.normalize('/foo/bar//baz/asdf/quux/..')\n// returns\n'/foo/bar/baz/asdf'
\n", "signatures": [ { "params": [ { "name": "p" } ] } ] }, { "textRaw": "path.join([path1], [path2], [...])", "type": "method", "name": "join", "desc": "

Join all arguments together and normalize the resulting path.\nNon-string arguments are ignored.\n\n

\n

Example:\n\n

\n
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')\n// returns\n'/foo/bar/baz/asdf'\n\npath.join('foo', {}, 'bar')\n// returns\n'foo/bar'
\n", "signatures": [ { "params": [ { "name": "path1", "optional": true }, { "name": "path2", "optional": true }, { "name": "...", "optional": true } ] } ] }, { "textRaw": "path.resolve([from ...], to)", "type": "method", "name": "resolve", "desc": "

Resolves to to an absolute path.\n\n

\n

If to isn't already absolute from arguments are prepended in right to left\norder, until an absolute path is found. If after using all from paths still\nno absolute path is found, the current working directory is used as well. The\nresulting path is normalized, and trailing slashes are removed unless the path\ngets resolved to the root directory. Non-string arguments are ignored.\n\n

\n

Another way to think of it is as a sequence of cd commands in a shell.\n\n

\n
path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')
\n

Is similar to:\n\n

\n
cd foo/bar\ncd /tmp/file/\ncd ..\ncd a/../subfile\npwd
\n

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

\n

Examples:\n\n

\n
path.resolve('/foo/bar', './baz')\n// returns\n'/foo/bar/baz'\n\npath.resolve('/foo/bar', '/tmp/file/')\n// returns\n'/tmp/file'\n\npath.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')\n// if currently in /home/myself/node, it returns\n'/home/myself/node/wwwroot/static_files/gif/image.gif'
\n", "signatures": [ { "params": [ { "name": "from ...", "optional": true }, { "name": "to" } ] } ] }, { "textRaw": "path.relative(from, to)", "type": "method", "name": "relative", "desc": "

Solve the relative path from from to to.\n\n

\n

At times we have two absolute paths, and we need to derive the relative\npath from one to the other. This is actually the reverse transform of\npath.resolve, which means we see that:\n\n

\n
path.resolve(from, path.relative(from, to)) == path.resolve(to)
\n

Examples:\n\n

\n
path.relative('C:\\\\orandea\\\\test\\\\aaa', 'C:\\\\orandea\\\\impl\\\\bbb')\n// returns\n'..\\\\..\\\\impl\\\\bbb'\n\npath.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')\n// returns\n'../../impl/bbb'
\n", "signatures": [ { "params": [ { "name": "from" }, { "name": "to" } ] } ] }, { "textRaw": "path.dirname(p)", "type": "method", "name": "dirname", "desc": "

Return the directory name of a path. Similar to the Unix dirname command.\n\n

\n

Example:\n\n

\n
path.dirname('/foo/bar/baz/asdf/quux')\n// returns\n'/foo/bar/baz/asdf'
\n", "signatures": [ { "params": [ { "name": "p" } ] } ] }, { "textRaw": "path.basename(p, [ext])", "type": "method", "name": "basename", "desc": "

Return the last portion of a path. Similar to the Unix basename command.\n\n

\n

Example:\n\n

\n
path.basename('/foo/bar/baz/asdf/quux.html')\n// returns\n'quux.html'\n\npath.basename('/foo/bar/baz/asdf/quux.html', '.html')\n// returns\n'quux'
\n", "signatures": [ { "params": [ { "name": "p" }, { "name": "ext", "optional": true } ] } ] }, { "textRaw": "path.extname(p)", "type": "method", "name": "extname", "desc": "

Return the extension of the path, from the last '.' to end of string\nin the last portion of the path. If there is no '.' in the last portion\nof the path or the first character of it is '.', then it returns\nan empty string. Examples:\n\n

\n
path.extname('index.html')\n// returns\n'.html'\n\npath.extname('index.')\n// returns\n'.'\n\npath.extname('index')\n// returns\n''
\n", "signatures": [ { "params": [ { "name": "p" } ] } ] } ], "properties": [ { "textRaw": "path.sep", "name": "sep", "desc": "

The platform-specific file separator. '\\\\' or '/'.\n\n

\n

An example on *nix:\n\n

\n
'foo/bar/baz'.split(path.sep)\n// returns\n['foo', 'bar', 'baz']
\n

An example on Windows:\n\n

\n
'foo\\\\bar\\\\baz'.split(path.sep)\n// returns\n['foo', 'bar', 'baz']
\n" }, { "textRaw": "path.delimiter", "name": "delimiter", "desc": "

The platform-specific path delimiter, ; or ':'.\n\n

\n

An example on *nix:\n\n

\n
console.log(process.env.PATH)\n// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'\n\nprocess.env.PATH.split(path.delimiter)\n// returns\n['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
\n

An example on Windows:\n\n

\n
console.log(process.env.PATH)\n// 'C:\\Windows\\system32;C:\\Windows;C:\\Program Files\\nodejs\\'\n\nprocess.env.PATH.split(path.delimiter)\n// returns\n['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\nodejs\\']
\n" } ], "type": "module", "displayName": "Path" } ] }