I have a file on this path:
~/Downloads/flightlog_2017-71-19_19747.txt
But when i try to write or check if it exist:
fs.existsSync('~/Downloads/flightlog_2017-71-19_19747.txt')
It always return false
If I do in terminal:
$ nano ~/Downloads/flightlog_2017-71-19_19747.txt
This works fine
I don't think using ~ to reference a users' Home directory is supported in Node. As there is no equivalent command in Windows.
You can follow this thread for the complete discussion. https://github.com/nodejs/node/issues/684
For the Time being you can use untildify npm package for your needs.
~
is special to the shell (terminal process), expanding to the current home directory, but it is not special otherwise. You'll need to use an absolute path, or a relative path (relative to the process).
For instance, assuming ~
maps to /home/arti
:
fs.existsSync('/home/arti/Downloads/flightlog_2017-71-19_19747.txt')
Or if you're running the process in ~/example
, then this relative path would work:
fs.existsSync('../Downloads/flightlog_2017-71-19_19747.txt')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With