npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cldmv/droidsock

v2.2.1

Published

Complete Node.js implementation of the Android Debug Bridge (ADB) protocol

Readme

@cldmv/droidsock

DroidSock is a complete, from-scratch implementation of the Android Debug Bridge (ADB) protocol in Node.js. This library provides full ADB functionality including device connection, RSA authentication, shell command execution, and file transfers - eliminating clicking sounds on Android TV devices!

It talks to devices directly over TCP, with no adb binary or ADB server in between, and composes its protocol layers into a single API tree with @cldmv/slothlet, so every connected device becomes its own persistent API leaf.

ADB over the wire, in pure Node.js - no adb binary required.

npm version npm downloads GitHub downloads Last commit npm last update coverage

[!NOTE] Current status:

  • Shell + streaming: Stable - command execution, interactive shells, and log / process streaming all work over the real ADB protocol.
  • File transfer: mkdir / remove / move / copy / chmod / diskUsage / find / stat work today via shell commands. list prefers a binary-safe SYNC-based implementation with automatic shell fallback.
  • Experimental: push / pull / pushV2 / pullV2 / listSync / listV2 / statV2 (real ADB SYNC sub-protocol usage, both the legacy 32-bit and newer 64-bit variants), device.reboot(), device.forward() / device.reverse(), device.install() (both the classic push-then-install and modern streaming install paths), and pairing.pair() (Wi-Fi pairing) are all implemented - built from the ADB protocol spec and covered by unit tests (several exercised against real loopback TCP / TLS servers, not purely mocks) - but none of them have been run against a real device yet. See #1.

Contributors Sponsor shinrai


✨ What's New

Latest: v2.2.1 (November 2026)

  • @cldmv/slothlet kept below 3.24.0 - slothlet 3.24.0 hands sockets back as proxies, so device.connect() threw TypeError: Illegal invocation on any install that resolved it (slothlet#708). The range is now >=3.22.1 <3.24.0; no droidsock code changed (#112).
  • Suite runs against the build - npm run test:dist runs the Vitest suite against dist/, and npm test includes it (#107).
  • View full v2.2.1 Changelog

Recent Releases

  • v2.2.0 (November 2026) - CLDMV library layout (src/index.mjs / src/index.cjs entries, tsup-built dist/); @cldmv/droidsock/main is a deprecated alias of the root (Changelog)
  • v2.1.0 (October 2026) - device lifecycle events, opt-in auto-reconnect with backoff, TCP keepalive and an optional heartbeat; engines.node rose to >=22.15.0 (Changelog)
  • v2.0.3 (October 2026) - index.cjs loads the ESM entry with a plain require() and fails clearly without require(esm); @cldmv/droidsock/devcheck is no longer exported or published (Changelog)
  • v2.0.2 (October 2026) - Dev tooling only: shared CLDMV fix-headers config and a required PR check that never reports as skipped, no runtime change (Changelog)

📚 For complete version history and detailed release notes, see the docs/changelog/ folder.


🚀 Key Features

  • ✅ Complete ADB Protocol: TCP connection, CNXN / AUTH handshake, and stream multiplexing implemented from scratch
  • ✅ RSA Authentication: Automatic key generation and ADB-specific signature / public-key formatting
  • ✅ Stream Multiplexing: Multiple concurrent operations over a single connection
  • ✅ Shell Commands: Execute commands, stream output, interactive sessions
  • ✅ File Operations: Shell-based mkdir / remove / move / copy / chmod / diskUsage / find, plus binary-safe SYNC-based list, and experimental push / pull (legacy 32-bit) / pushV2 / pullV2 / listV2 / statV2 (64-bit)
  • ✅ Reboot (experimental): Real reboot: service, including bootloader / recovery / sideload modes
  • ✅ Port Forwarding (experimental): adb forward/adb reverse-equivalent TCP tunneling, both directions
  • ✅ APK Install (experimental): adb install-equivalent local APK installation - classic push-then-install and modern streaming (exec:cmd package install) paths
  • ✅ Wi-Fi Pairing (experimental): adb pair-equivalent PIN-based pairing (SPAKE2-over-Ed25519 + TLS 1.3) for Android 11+ wireless debugging
  • ✅ Device Discovery (experimental): discover.subnet() CIDR sweep and discover.mdns() for devices advertising wireless debugging, plus support for multiple devices via configuration
  • ✅ Error Handling: Robust error handling and connection recovery

📦 Installation

Requirements

  • Node.js v22.15.0 or higher (the package's engines.node floor, set by its @cldmv/slothlet dependency)
  • Both import and require() are supported. require() loads the ESM entry through Node's synchronous require(esm), which every supported Node.js version (22.15+) provides; on older versions, load the package with import() instead.
  • Developing this package needs Node.js 22.22.0 or later (devEngines).

Install

npm install @cldmv/droidsock

🚀 Quick Start

import droidsock from "@cldmv/droidsock";

// Create the API instance
const api = await droidsock();

// Connect to a device
const device = await api.device.connect("10.6.0.108", 5555);

// Execute a shell command
const output = await device.shell("ls -la");
console.log(output);

// Convenience getters
const model = await device.getModel();
const version = await device.getAndroidVersion();

// Stream commands
const logcat = device.logcat({
	onData: (data) => console.log(data)
});

// Clean up
await device.disconnect();

CommonJS works the same way: const droidsock = require("@cldmv/droidsock") (also available as createDroidSock).

@cldmv/droidsock/main is a deprecated alias of @cldmv/droidsock: it exports the same functions and prints a DeprecationWarning (code CLDMV_DROIDSOCK_MAIN) once per process. Import @cldmv/droidsock instead; the alias is removed in the next major version.


⚙️ Device Configuration

The example scripts read device addresses from references/devices.json. The folder is git-ignored, so create the file yourself:

{
	"livingroom": {
		"name": "Living Room TV",
		"host": "10.6.0.108",
		"port": 5555,
		"description": "Main living room Android TV"
	},
	"bedroom": {
		"name": "Master Bedroom TV",
		"host": "10.6.0.118",
		"port": 5555,
		"description": "Master bedroom Android TV"
	},
	"default": "livingroom"
}

📘 API Reference

droidsock(options) (also createDroidSock) creates the API instance; api.device.connect(host, port, options) connects to a device (IPv4 or IPv6) and returns its live leaf - also reachable afterward at api.devices["<host>_<port>"] (a . becomes _, a : becomes __) - exposing connection state, shell execution / streaming, file operations (push / pull / list / stat), reboot, port forwarding, and APK install. api.device.disconnect(host, port) tears down one device's connection without forgetting it - reconnect later with connect() on the same host:port, no need to re-supply options; api.device.remove(host, port) forgets it entirely. api.devices.list() / disconnect() (all) / remove() (all) / get(idOrLeaf) manage the set of known devices as a whole.

📚 See docs/API.md for the full method reference, including every option and the experimental / scope caveats on push / pull / list / forward / reverse / install.


💡 Examples

Basic Usage

# Run basic example with default device
node --conditions=droidsock-dev examples/basic-usage.mjs

# Run with specific device
node --conditions=droidsock-dev examples/basic-usage.mjs livingroom

The examples import @cldmv/droidsock by name. --conditions=droidsock-dev runs them against src/; without it they load the build in dist/ (run npm run build first). See Development.

Streaming Commands

# Stream logcat
node --conditions=droidsock-dev examples/streaming-example.mjs logcat

# Stream top command
node --conditions=droidsock-dev examples/streaming-example.mjs top

# File transfer demo
node --conditions=droidsock-dev examples/streaming-example.mjs files

🏗️ Architecture

src/index.mjs is the package entry (src/index.cjs is the CommonJS entry, which loads it through require(esm)) and re-exports the factory from src/droidsock.mjs, which composes the layers below into a single api tree via @cldmv/slothlet:

  1. Connection Layer (src/api/connection.mjs): TCP socket + CNXN / AUTH handshake
  2. Authentication Layer (src/api/auth.mjs): RSA key management and ADB signature / public-key formatting
  3. Stream Layer (src/api/stream.mjs): ADB stream multiplexing (OPEN / WRTE / OKAY / CLSE)
  4. Shell Layer (src/api/shell.mjs): Command execution, streaming, and interactive shell APIs
  5. Files Layer (src/api/files.mjs): Shell-based file operations, a binary-safe SYNC LIST implementation with automatic shell fallback, and an experimental ADB SYNC sub-protocol implementation for real binary transfer (push / pull) - not yet validated against a real device
  6. Reboot Layer (src/api/reboot.mjs): Real ADB reboot: service
  7. Forward Layer (src/api/forward.mjs): TCP port forwarding (host → device) via the tcp: service
  8. Reverse Layer (src/api/reverse.mjs): TCP port forwarding (device → host) via reverse:forward:/reverse:killforward: and the Stream layer's device-initiated stream handling
  9. Install Layer (src/api/install.mjs): Local APK install, composed from the Files and Shell layers
  10. Pairing Layer (src/api/pairing.mjs): Wi-Fi pairing (adb pair equivalent) - a separate TLS 1.3 + SPAKE2 protocol reusing the Authentication layer's persistent RSA identity, not composed with any of the layers above
  11. Device / Devices Layers (src/api/device.mjs, src/api/devices.mjs): High-level per-device API composing the layers above, split by single-target (device.connect/disconnect/remove) vs. collection-wide (devices.list/disconnect/remove/get) operations. Each device is a real, persistent slothlet leaf at api.devices.<sanitized host_port>, assigned there by connect() rather than held in a private module variable, so its methods keep working self/context access exactly like any other leaf - the leaf outlives any one connection, and only remove() unmounts it
  12. Config / Log Layers (src/api/config.mjs, src/api/log.mjs): Shared configuration and logging

📚 See docs/PROTOCOL.md for wire-level protocol details (packet structure, auth flow, SYNC sub-protocol framing, reboot / forward service usage).


🛠 Troubleshooting

Connection Issues

  • Ensure device is on same network
  • Enable "ADB over network" in developer options
  • Check firewall settings
  • Verify IP address and port

Authentication Issues

  • Delete existing keys to force re-authorization: rm -rf ~/.adb
  • Ensure device shows authorization dialog
  • Check device storage permissions

Common Errors

  • "Command timeout": Increase timeout in options
  • "Stream not open": Ensure connection is established
  • "File not found": Check paths and permissions

🧪 Development

The implementation is built directly from the public ADB protocol documentation (AOSP SYNC.TXT and the wire-protocol references), cross-checked against Google's own reference client (google/python-adb) where the public docs are ambiguous, and covered by a mocked Vitest suite. The core connection / shell / stream-multiplexing path has real device usage behind it; the newer SYNC-protocol and service additions (push / pull / listSync / reboot / forward / install) have not yet been run against a real device - see the status note at the top of this README and #1.

The source lives in src/: src/index.mjs is the ESM entry and src/index.cjs the CommonJS entry. npm run build (tsup) writes dist/, which mirrors src/ file by file because slothlet scans dist/api/ at runtime; dist/index.cjs is a verbatim copy of src/index.cjs. Only dist/ and types/ are published.

In a checkout, @cldmv/droidsock resolves to dist/ by default. The droidsock-dev export condition switches it to src/:

| Run | Resolves to | | ------------------------------------------------ | --------------------------------------------------------------- | | node app.mjs | dist/index.mjs (ERR_MODULE_NOT_FOUND until npm run build) | | node --conditions=droidsock-dev app.mjs | src/index.mjs | | require("@cldmv/droidsock") with the condition | src/index.cjs → src/index.mjs |

Set it once per shell with export NODE_OPTIONS=--conditions=droidsock-dev. npm test runs the Vitest suite against src/ (the Vitest config passes the condition) and then npm run test:cjs, which builds dist/ and checks it with node --test, and npm run test:dist builds dist/ and runs the Vitest suite against it (npm test includes both).


📚 Documentation

  • API Reference - every method and option, with the experimental and scope caveats
  • Protocol Details - packet structure, auth flow, SYNC sub-protocol framing, reboot / forward service usage
  • Changelog - per-version release notes

CodeFactor OpenSSF Scorecard npms.io score npm unpacked size Repo size


🤝 Contributing

This is a complete implementation of the ADB protocol. For improvements or bug fixes, please submit issues or pull requests.

Contributors Sponsor shinrai


🔗 Links


📄 License

GitHub license npm license

Apache-2.0 - see LICENSE for details.