# balena-register-device

> Balena device registration utilities

Latest version **9.0.35** (published 2026-06-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install balena-register-device
pnpm add balena-register-device
yarn add balena-register-device
bun add balena-register-device
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 9.0.35 |
| Published | 2026-06-25 |
| First published | 2019-04-11 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 3 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3 |
| Author | Juan Cruz Viotti |
| Maintainers | balena.io |
| Keywords | resin, balena, device, register |

## Links

- npm: https://www.npmjs.com/package/balena-register-device
- Repository: https://github.com/balena-io-modules/balena-register-device
- Issues: https://github.com/balena-io-modules/balena-register-device/issues
- npm.io page: https://npm.io/package/balena-register-device

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^13.0.0
- [tslib](https://npm.io/package/tslib.md) ^2.2.0
- [typed-error](https://npm.io/package/typed-error.md) ^3.2.1

## Recent versions

- 9.0.35 (latest) — 2026-06-25
- 9.0.36-build-renovate-chai-6-x-2b9c75a51973fd0ba6a72bdf53479b26311ec12c-1 (build-renovate-chai-6-x) — 2026-06-25
- 9.0.36-build-renovate-uuid-14-x-21e146aeb2cd916ac395abefbd6507965491afec-1 (build-renovate-uuid-14-x) — 2026-06-25
- 9.0.35-build-renovate-chai-as-promised-8-x-5515ea018663d08db2b84460a9c9915e6c40d7b6-1 (build-renovate-chai-as-promised-8-x) — 2026-06-13
- 9.0.34-build-renovate-chai-5-x-643c62c38e5c71dd78e39d317b8b36f974d3ab80-1 (build-renovate-chai-5-x) — 2026-06-10
- 9.0.33-build-renovate-pin-dependencies-4b525f35af62aa32cd58db4e67ab1fb22eed5b60-1 (build-renovate-pin-dependencies) — 2026-06-10
- 9.0.33-build-renovate-npm-uuid-vulnerability-cc37e4c50572a1495164363cf3d64af10f8325e9-1 (build-renovate-npm-uuid-vulnerability) — 2026-05-04
- 9.0.32-build-kyle-revert-flowzone-to-master-2d2ee80c167ac1d32b59a9df6b4ff33ca2fcdb55-1 (build-kyle-revert-flowzone-to-master) — 2026-03-26
- 9.0.31-build-renovate-github-actions-fe9a4fce3bcab3ba364a5940f7cccaab5700570e-1 (build-renovate-github-actions) — 2026-03-26
- 9.0.16-build-renovate-patch-balena-config-karma-2c00ec989886848fb34f04ddea64d57071c5c906-1 (build-renovate-patch-balena-config-karma) — 2026-02-22
- 9.0.15-build-add-npm-oidc-permissions-c2d2a30df67c674ea6f6cc8548efaf29a9c69da9-1 (build-add-npm-oidc-permissions) — 2026-02-18
- 9.0.14-build-remove-stub-dep-9f1fc0290ff40c9364d2e999725f542d95c1cd66-1 (build-remove-stub-dep) — 2025-11-24
- 9.0.13-build-renovate-major-12-uuid-89225952ed240433bb4d033bae86a3f1a23a6b7b-1 (build-renovate-major-12-uuid) — 2025-11-12
- 9.0.13-build-renovate-major-13-uuid-367a6ea7d786d9ca3626e6d60e26b9f3625cb6cb-1 (build-renovate-major-13-uuid) — 2025-11-12
- 9.0.12-build-renovate-major-11-mocha-5df3c840397857a219571fc7f20f7140038ce91b-1 (build-renovate-major-11-mocha) — 2025-11-11
- … 147 more at https://npm.io/package/balena-register-device/versions

## README

��balena-register-device
=====================

> Balena device registration utilities.

[![npm version](https://badge.fury.io/js/balena-register-device.svg)](http://badge.fury.io/js/balena-register-device)
[![dependencies](https://david-dm.org/balena-io-modules/balena-register-device.svg)](https://david-dm.org/balena-io-modules/balena-register-device.svg)
[![Build Status](https://travis-ci.org/balena-io-modules/balena-register-device.svg?branch=master)](https://travis-ci.org/balena-io-modules/balena-register-device)
[![Build status](https://ci.appveyor.com/api/projects/status/uh8bg45pxxyx2qif/branch/master?svg=true)](https://ci.appveyor.com/project/resin-io/balena-register-device/branch/master)

Installation
------------

Install `balena-register-device` by running:

```sh
$ npm install --save balena-register-device
```

Documentation
-------------

Balena-Register-Device exports a factory function, which must be called with a dependencies object, containing a configured [`balena-request`](https://github.com/balena-io-modules/balena-request) instance.

Example:
```coffee
deviceRegister = require('balena-register-device')({
	request: request # An instantiated balena-request instance
})
```

### deviceRegister.generateUniqueKey()

Generate a random key, useful for both uuid and api key.

Example:
```coffee
randomKey = deviceRegister.generateUniqueKey()
# randomKey is a randomly generated key that can be used as either a uuid or an api key
console.log(randomKey)
```

### deviceRegister.register(Object options, Function callback)

Register a device with Balena.

**Notice**: You can use this function as a promise if you omit the `callback` argument.

The `options` object requires the following properties:

- `Number userId`: The user id - optional.
- `Number applicationId`: The application id.
- `String uuid`: The device's UUID.
- `String deviceType`: The device type slug.
- `String deviceApiKey`: The API key to create for the newly registered device.
- `String provisioningApiKey`: The provisioning API Key.
- `String apiEndpoint`: The API endpoint.

The `callback` gets called with two arguments: `(error, deviceInfo)`, where `deviceInfo` is an object containing one property: the `id` for the device that was just registered.

Example:

```coffee
deviceRegister.register
		userId: 199
		applicationId: 10350
		uuid: '...'
		deviceType: 'raspberry-pi'
		deviceApiKey: '...'
		provisioningApiKey: '...'
		apiEndpoint: 'https://api.balena-cloud.com'
	, (error, deviceInfo) ->
		throw error if error?
		console.log(deviceInfo) # { id }
```

Tests
-----

Run the test suite by doing:

```sh
$ npm test
```

Contribute
----------

- Issue Tracker: [github.com/balena-io-modules/balena-register-device/issues](https://github.com/balena-io-modules/balena-register-device/issues)
- Source Code: [github.com/balena-io-modules/balena-register-device](https://github.com/balena-io-modules/balena-register-device)

Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning:

```sh
$ npm run lint
```

Support
-------

If you're having any problem, please [raise an issue](https://github.com/balena-io-modules/balena-register-device/issues/new) on GitHub.

License
-------

The project is licensed under the Apache 2.0 license.

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