According to the docs, node.js's path.resolve
function converts the passed argument to an absolute path. However, when I pass it the non-existent file ''
, it returns the current working directory:
~$ node -v
v0.8.14
~$ node
> require('path').resolve('')
'/Users/perimosocordiae'
> require('fs').statSync('')
Error: ENOENT, no such file or directory ''
Is this intended behavior? Are there any other cases in which a "resolved" path will exist when the input path doesn't, or vice versa?
Other parts of the documentation say:
If after using all
from
paths still no absolute path is found, the current working directory is used as well.
and
the different paths don't need to exist and may also be files.
path.resolve
can be thought of, as the docs, say, as a series of cd
commands--e.g., what would happen if I started at from
(or process.cwd()
if no from
is specified, as in your example) and manipulated that path with the string in to
.