5

I'm trying to check if a directory exists as part of a command-line app in node.js. However, fs doesn't seem to understand ~/. For example, the following returns false...

> fs.existsSync('~/Documents')
false

...but this returns true...

> fs.existsSync('/Users/gtmtg/Documents')
true

...even though they're both the same thing.

Why does this happen, and is there are workaround for this? Thanks in advance!

gtmtg
  • 2,960
  • 2
  • 21
  • 35
  • 3
    [It's a Bash feature called "tilde expansion". It's a function of the shell, not the OS.](http://stackoverflow.com/a/1660054/612202) – dan-lee Sep 16 '12 at 22:33

1 Answers1

8

That's because ~/ is supported by the command shell, not the file system APIs.

JohnnyHK
  • 290,447
  • 61
  • 595
  • 453