Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/user-home
Get the path to the user home directory
https://github.com/sindresorhus/user-home
Last synced: 3 months ago
JSON representation
Get the path to the user home directory
- Host: GitHub
- URL: https://github.com/sindresorhus/user-home
- Owner: sindresorhus
- License: mit
- Archived: true
- Created: 2014-08-03T17:21:06.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T13:35:08.000Z (over 3 years ago)
- Last Synced: 2024-05-22T18:24:39.681Z (7 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 160
- Watchers: 6
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-cross-platform-nodejs - user-home - Get the path to the user home directory. Cross-platform. (Libraries / Environment)
- awesome-nodejs-cn - user-home - Get the path to the user home directory. (包 / Command-line utilities)
- awesome-nodejs - user-home - Get the path to the user home directory. Cross-platform. ![](https://img.shields.io/github/stars/sindresorhus/user-home.svg?style=social&label=Star) (Repository / Environment)
- awesome-nodejs-precise - user-home - home .svg?style=social&label=Star&maxAge=2592000?style=flat-square)]() | Get the path to the user home directory. | (Packages / Command-line utilities)
README
Deprecated. Just use `import {homedir} from 'os';`.
---
# user-home
> Get the path to the user home directory
## Install
```
$ npm install user-home
```## Usage
```js
const userHome = require('user-home');console.log(userHome);
//=> '/Users/sindresorhus'
```Returns `null` in the unlikely scenario that the home directory can't be found.
## FAQ
### Why not just use the `os-home` module?
This module was made long before [`os-homedir`](https://github.com/sindresorhus/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](https://github.com/sindresorhus/ama/issues/10#issuecomment-117766328), so doesn't matter. Use whichever you prefer. I'm going to continue using this one.
## Related
- [user-home-cli](https://github.com/sindresorhus/user-home-cli) - CLI for this module
- [home-or-tmp](https://github.com/sindresorhus/home-or-tmp) - Get the user home directory with fallback to the system temp directory