# @homebridge/dbus-native

> D-bus protocol implementation in native javascript

Latest version **0.7.9** (published 2026-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @homebridge/dbus-native
pnpm add @homebridge/dbus-native
yarn add @homebridge/dbus-native
bun add @homebridge/dbus-native
```

Provides the command `dbus2js`.

## 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; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.7.9 |
| Published | 2026-08-15 |
| First published | 2022-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 87.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 16 |
| Author | Andrey Sidorov |
| Maintainers | oznu, northernman, supereg, khaost, ebaauw, dustin.greif, nfarina, bwp91 |
| Keywords | dbus, dcop, d-bus, rpc, gnome, kde |

## Links

- npm: https://www.npmjs.com/package/@homebridge/dbus-native
- Repository: https://github.com/homebridge/dbus-native
- Homepage: https://github.com/homebridge/dbus-native#readme
- Issues: https://github.com/homebridge/dbus-native/issues
- npm.io page: https://npm.io/package/@homebridge/dbus-native

## Dependencies (6)

- [hexy](https://npm.io/package/hexy.md) ^0.4.0
- [long](https://npm.io/package/long.md) ^5.3.2
- [xml2js](https://npm.io/package/xml2js.md) ^0.6.2
- [minimist](https://npm.io/package/minimist.md) ^1.2.8
- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.2.1
- [event-stream](https://npm.io/package/event-stream.md) ^4.0.1

## Recent versions

- 0.7.9 (latest) — 2026-08-15
- 0.7.9-beta.3 (beta) — 2026-08-15
- 0.7.9-beta.2 — 2026-08-15
- 0.7.9-beta.1 — 2026-08-15
- 0.7.9-beta.0 — 2026-08-08
- 0.7.8 — 2026-07-25
- 0.7.7 — 2026-07-08
- 0.7.6 — 2026-05-25
- 0.7.6-beta.4 — 2026-05-24
- 0.7.6-beta.3 — 2026-05-24
- 0.7.6-beta.2 — 2026-05-09
- 0.7.6-beta.1 — 2026-05-09
- 0.7.6-beta.0 — 2026-05-08
- 0.7.5 — 2026-05-04
- 0.7.4 — 2026-03-29
- … 11 more at https://npm.io/package/@homebridge/dbus-native/versions

## README

<p align="center">
  <a href="https://homebridge.io"><img src="https://raw.githubusercontent.com/homebridge/branding/latest/logos/homebridge-color-round-stylized.png" height="140"></a>
</p>

<span align="center">

# D-Bus Native

[![Greenkeeper badge](https://badges.greenkeeper.io/sidorares/dbus-native.svg)](https://greenkeeper.io/)
[![Node Test](https://github.com/homebridge/dbus-native/actions/workflows/run-test.yml/badge.svg)](https://github.com/homebridge/dbus-native/actions/workflows/run-test.yml)

</span>

D-bus protocol client and server for node.js

Fork Status
------------

This fork is maintained with the following changes:
* Removed the optional `abstract-socket` dependency for faster installs
* Moved to our `long.js` fork to work around a crash on `ARMv6` platforms running node 16.1+
* Updated dependencies (including `prettier`, which has made style changes to a lot of files)

Installation
------------

```shell
npm install dbus-native
```
or

```shell
git clone https://github.com/sidorares/node-dbus # clone the repo
cd node-dbus
npm install # install dependencies
sudo cp examples/com.github.sidorares.dbus.Example.conf /etc/dbus-1/system.d/ # if you want to test examples/service.js
```

Usage
------

Short example using desktop notifications service

```js
var dbus = require('dbus-native');
var sessionBus = dbus.sessionBus();
sessionBus
  .getService('org.freedesktop.Notifications')
  .getInterface(
    '/org/freedesktop/Notifications',
    'org.freedesktop.Notifications',
    function(err, notifications) {
      // dbus signals are EventEmitter events
      notifications.on('ActionInvoked', function() {
        console.log('ActionInvoked', arguments);
      });
      notifications.on('NotificationClosed', function() {
        console.log('NotificationClosed', arguments);
      });
      notifications.Notify(
        'exampl',
        0,
        '',
        'summary 3',
        'new message text',
        ['xxx yyy', 'test2', 'test3', 'test4'],
        [],
        5,
        function(err, id) {
          //setTimeout(function() { n.CloseNotification(id, console.log); }, 4000);
        }
      );
    }
  );
```

API
---

### Low level messaging: bus connection

`connection = dbus.createClient(options)`

options:
   - socket - unix socket path
   - port - TCP port
   - host - TCP host
   - busAddress - encoded bus address. Default is `DBUS_SESSION_BUS_ADDRESS` environment variable. See http://dbus.freedesktop.org/doc/dbus-specification.html#addresses
   - authMethods - array of authentication methods, which are attempted in the order provided (default:['EXTERNAL', 'DBUS_COOKIE_SHA1', 'ANONYMOUS'])
   - ayBuffer - boolean (default:true): if true 'ay' dbus fields are returned as buffers
   - ReturnLongjs - boolean (default:false): if true 64 bit dbus fields (x/t) are read out as Long.js objects, otherwise they are converted to numbers (which should be good up to 53 bits)
   - ( TODO: add/document option to use adress from X11 session )

connection has only one method, `message(msg)`

message fields:
   - type - methodCall, methodReturn, error or signal
   - path - object path
   - interface
   - destination
   - sender
   - member
   - serial
   - signature
   - body
   - errorName
   - replySerial

connection signals:
   - connect - emitted after successful authentication
   - message
   - error

example:

```js
var dbus = require('dbus-native');
var conn = dbus.createConnection();
conn.message({
  path: '/org/freedesktop/DBus',
  destination: 'org.freedesktop.DBus',
  interface: 'org.freedesktop.DBus',
  member: 'Hello',
  type: dbus.messageType.methodCall
});
conn.on('message', function(msg) {
  console.log(msg);
});
```

### Note on INT64 'x' and UINT64 't'
Long.js is used for 64 Bit support. https://github.com/dcodeIO/long.js
The following javascript types can be marshalled into 64 bit dbus fields:
   - typeof 'number' up to 53bits
   - typeof 'string' (consisting of decimal digits with no separators or '0x' prefixed hexadecimal) up to full 64bit range
   - Long.js objects (or object with compatible properties)

By default 64 bit dbus fields are unmarshalled into a 'number' (with precision loss beyond 53 bits). Use {ReturnLongjs:true} option to return the actual Long.js object and preserve the entire 64 bits.

### Links
   - http://cgit.freedesktop.org/dbus - freedesktop reference C library
   - https://github.com/guelfey/go.dbus
   - https://github.com/Shouqun/node-dbus - libdbus
   - https://github.com/Motorola-Mobility/node-dbus - libdbus
   - https://github.com/izaakschroeder/node-dbus - libdbus
   - https://github.com/agnat/node_libdbus
   - https://github.com/agnat/node_dbus - native js
   - https://github.com/cocagne/txdbus - native python + twisted
   - http://search.cpan.org/~danberr/Net-DBus-1.0.0/ (seems to be native, but requires libdbus?)
   - https://github.com/mvidner/ruby-dbus (native, sync)
   - http://www.ndesk.org/DBusSharp (C#/Mono)
   - https://github.com/lizenn/erlang-dbus/ - erlang
   - https://github.com/mspanc/dbux/ - elixir
   - http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html - Blog post about sb-bus and D-Bus in general

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