Fs in Node.js Doesn't understand ~ /

I am trying to check if a directory exists as part of a command line application in node.js. However, fs does not seem to understand ~/ . For example, the following returns false ...

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

... but this returns true ...

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

... although they are both the same.

Why is this happening, and are there any workarounds for this? Thanks in advance!

+4
source share
1 answer

This is because ~/ supported by the shell, and not by the file system APIs.

+6
source

Source: https://habr.com/ru/post/1434502/


All Articles