# node-machine-id

> Unique machine (desktop) id (no admin privileges required).

Latest version **1.1.12** (published 2019-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-machine-id
pnpm add node-machine-id
yarn add node-machine-id
bun add node-machine-id
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2019-05-29 |
| First published | 2016-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 629 |
| Author | Aleksandr Komlev |
| Maintainers | automation-stack |
| Keywords | unique id, license, trial, user license, user id, machine id, unique platform id, node platform id, unique identifier, restrictions, electron id, nw.js id |

## Links

- npm: https://www.npmjs.com/package/node-machine-id
- Repository: https://github.com/automation-stack/node-machine-id
- Homepage: https://github.com/automation-stack/node-machine-id#readme
- Issues: https://github.com/automation-stack/node-machine-id/issues
- npm.io page: https://npm.io/package/node-machine-id

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.12 (latest) — 2019-05-29
- 1.1.10 — 2018-01-16
- 1.1.9 — 2017-07-17
- 1.1.8 — 2017-07-12
- 1.1.7 — 2017-06-22
- 1.1.6 — 2017-06-19
- 1.1.4 — 2017-01-31
- 1.1.3 — 2016-12-30
- 1.1.2 — 2016-11-23
- 1.1.1 — 2016-09-23
- 1.1.0 — 2016-09-04

## README

**Cross-platform unique machine (desktop) id discovery**


## Use cases
- Software restrictions
- Installation tracking

## Features
- Hardware independent
- Unique within the OS installation
- No elevated rights required
- No external dependencies and does not require any native bindings
- Cross-platform (OSx, Win, Linux)

## How it works

Module based on OS native UUID/GUID which used for internal needs.

**All others approaches requires elevated rights or much depends on hardware components, but this approach summarize the methods of selecting the most reliable unique identifier**

- **Win32/64** uses key ```MachineGuid``` in registry
```HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography``` **(can be changed by administrator but with unpredictable consequences)**
>   It is generated during OS installation and won't change unless you make another OS
>   updates or reinstall. Depending on the OS version it may contain the network adapter
>   MAC address embedded (plus some other numbers, including random), or a pseudorandom number.

- **OSx** uses ```IOPlatformUUID``` (the same Hardware UUID)
``` ioreg -rd1 -c IOPlatformExpertDevice ```
>   Value from I/O Kit registry in IOPlatformExpertDevice class

- **Linux** uses ```/var/lib/dbus/machine-id``` **(can be changed by ```root``` but with unpredictable consequences)**
http://man7.org/linux/man-pages/man5/machine-id.5.html
>   The /var/lib/dbus/machine-id file contains the unique machine ID of the local
>   system that is set during installation. The machine ID is a single
>   newline-terminated, hexadecimal, 32-character, lowercase machine ID
>   string. When decoded from hexadecimal, this corresponds with a
>   16-byte/128-bit string.
>
>   The machine ID is usually generated from a random source during
>   system installation and stays constant for all subsequent boots.
>   Optionally, for stateless systems, it is generated during runtime at
>   early boot if it is found to be empty.
>
>   The machine ID does not change based on user configuration or when
>   hardware is replaced.


## Installation
```
npm install node-machine-id
```

## Usage
### Function: machineId(original)
- **original** ```<Boolean>```, If ```true``` return original value of machine id, otherwise return hashed value (sha-256), default: ```false```

### Function: machineIdSync(original);
- syncronous version of ```machineId```

```js
import {machineId, machineIdSync} from 'node-machine-id';

// Asyncronous call with async/await or Promise

async function getMachineId() {
    let id = await machineId();
    ...
}

machineId().then((id) => {
    ...
})

// Syncronous call

let id = machineIdSync()
// id = c24b0fe51856497eebb6a2bfcd120247aac0d6334d670bb92e09a00ce8169365
let id = machineIdSync({original: true})
// id = 98912984-c4e9-5ceb-8000-03882a0485e4
```
### Caveats

- Image-based environments have usually the same `machine-id`
> As a workaround you can generate new machine-ids for each instance (or container) with `dbus-uuidgen` and changed them in the respective > files: `/etc/machine-id` and `/var/lib/dbus/machine-id`. Thanks [@stefanhuber](https://github.com/stefanhuber)

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