Get real home directory in node.js.
Consider this situation:
You're user blah. You run command $ sudo -u foo node bar.js
and bar.js
will write some file in executor's (foo) home directory.
When you use process.env.HOME
in bar.js
with above command, you may won't get /home/foo
but get /home/blah
.
When you use os
module shown below:
const os = require("os");
console.log(os.homedir());
You may won't get /home/foo
but get /home/blah
too due to code of node.js and libuv.
You need this package to get the real home directory of current executor due to the situation above, and not only the situation above!
$ npm install -d --save real-homedir
Require this package first:
const homedir = require("real-homedir");
And just call it.
const hd = homedir();
Then you will get the real home directory!
You're welcome to make pull requests!
「雖然我覺得不怎麼可能有人會關注我」