Node: Linux/Unix: Resolve ~

Created on 23 Aug 2018  路  4Comments  路  Source: nodejs/node

Is your feature request related to a problem? Please describe.

nodejs does not resolve the ~ to the users home directory in linux/unix environments.
so the following code fails:

const fs = require(`fs`);
console.log(fs.readdirSync(`~`));

with:

Error: ENOENT: no such file or directory, scandir '~'
    at Object.fs.readdirSync (fs.js:895:3)

Describe the solution you'd like

Resolve ~ to the path of the users home directory.

feature request fs

Most helpful comment

I'm still -1 for the reasons given in the referenced issue.

All 4 comments

Maybe you can use something like this:

const os = require('os');
const fs = require('fs');
console.log(fs.readdirSync(os.homedir()));

And maybe you'll have to wait the publishment of this, if possible. So for a quick fixture for you @HappyStriker

This has been brought up a few times in the past, the last time at https://github.com/nodejs/node/issues/684.

I'm still -1 for the reasons given in the referenced issue.

I am fairly confident that we won鈥檛 get consensus on this feature, given the above comments and the previous issues on this topic, so I think it鈥檚 best to close this rather than have it linger around forever.

Was this page helpful?
0 / 5 - 0 ratings