# username

> Get the username of the current user

Latest version **7.0.0** (published 2023-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install username
pnpm add username
yarn add username
bun add username
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2023-11-14 |
| First published | 2014-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 144 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | username, user, login, name, logname, lname, whoami, shell, env, environment, variable |

## Links

- npm: https://www.npmjs.com/package/username
- Repository: https://github.com/sindresorhus/username
- Homepage: https://github.com/sindresorhus/username#readme
- Issues: https://github.com/sindresorhus/username/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/username

## Dependencies (2)

- [execa](https://npm.io/package/execa.md) ^8.0.1
- [memoize](https://npm.io/package/memoize.md) ^10.0.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 7.0.0 (latest) — 2023-11-14
- 6.0.0 — 2021-08-16
- 5.1.0 — 2019-06-12
- 5.0.0 — 2019-05-01
- 4.1.0 — 2019-01-26
- 4.0.0 — 2018-08-26
- 3.0.0 — 2017-06-15
- 2.3.0 — 2017-01-17
- 2.2.2 — 2016-06-22
- 2.2.1 — 2016-06-15
- 2.2.0 — 2016-06-01
- 2.1.0 — 2016-02-29
- 2.0.0 — 2016-01-23
- 1.0.1 — 2015-10-05
- 1.0.0 — 2014-08-14
- … 2 more at https://npm.io/package/username/versions

## README

# username

> Get the username of the current user

This module is meant for informational purposes and not for secure identification.

## Install

```sh
npm install username
```

*This package only works in Node.js, not in browsers.*

## Usage

```js
import {username} from 'username';

console.log(await username());
//=> 'sindresorhus'
```

## API

It first tries to get the username from the `SUDO_USER` `LOGNAME` `USER` `LNAME` `USERNAME` environment variables. Then falls back to `$ id -un` on macOS / Linux and `$ whoami` on Windows, in the rare case none of the environment variables are set. The result is cached.

### `username(): Promise<string | undefined>`

Returns the username.

### `usernameSync(): string | undefined`

Returns the username.

## Related

- [username-cli](https://github.com/sindresorhus/username-cli) - CLI for this module
- [fullname](https://github.com/sindresorhus/fullname) - Get the fullname of the current user

---
_Source: https://npm.io/package/username · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
