Most recently, a situation occurred: I have an environment variable for the directory path:
var fooDir = process.env.FOO_DIR;
and I want to make sure that this directory exists with synchronous mkdir (at some point later):
fs.mkdirSync(fooDir, mode);
however, if the user has provided an environment variable through realtive ~ / path node cannot solve it
export FOO_DIR='~/foodir'
Is there a way in node to resolve this without calling the exec call for the child process in a valid shell? currently my solution is to replace myself like this:
fooDir = fooDir.replace(/^~\//, process.env.HOME + '/');
just wondering if anyone has a better solution.
source share