Get the path to the user home directory
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.editorconfig minor tweaks May 2, 2015
.gitattributes init Aug 3, 2014
.gitignore init Aug 3, 2014
.jshintrc minor tweaks May 2, 2015
.travis.yml Update .travis.yml Feb 8, 2015
index.js depend on `os-homedir` ponyfill Jun 13, 2015
license init Aug 3, 2014
package.json update tests for latest AVA version Dec 31, 2015 add FAQ Oct 31, 2015
test.js update tests for latest AVA version Dec 31, 2015

user-home Build Status

Get the path to the user home directory


$ npm install --save user-home


var userHome = require('user-home');

//=> '/Users/sindresorhus'

Returns null in the unlikely scenario that the home directory can't be found.


Why not just use the os-home module?

This module was made long before os-homedir. When Node.js decided to add a native method for getting the user's home directory, I made a polyfill matching its API and decided to depend on it here, so not to have duplicate code. The main reason this one is still around is that lots of modules depend on it and I see no reason to inconvenience dependents by deprecating this. This one also gets the home directory on startup and returns a string rather than exposing a method, so it's faster, and I prefer this API. Modules are cheap in Node.js, so doesn't matter. Use whichever you prefer. I'm going to continue using this one.


  • user-home-cli - CLI for this module
  • home-or-tmp - Get the user home directory with fallback to the system temp directory


MIT © Sindre Sorhus