Skip to content

BoogeeDoo/real-homedir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real Homedir

Real Homedir Real Homedir Build Status Coverage Status License Dependency Status

Get real home directory in node.js.

Why This Package?

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.

$HOME

When you use process.env.HOME in bar.js with above command, you may won't get /home/foo but get /home/blah.

os.homedir()

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.

So

You need this package to get the real home directory of current executor due to the situation above, and not only the situation above!

Installation

$ npm install -d --save real-homedir

Usage

Require this package first:

const homedir = require("real-homedir");

And just call it.

const hd = homedir();

Then you will get the real home directory!

Contribution

You're welcome to make pull requests!

「雖然我覺得不怎麼可能有人會關注我」