Create client
ADB Server has its own sets of commands. AdbServerClient class is a TypeScript re-implementation of Google ADB Client, that provides a high-level API to interact with the Server.
Node.js Connectors
The @yume-chan/adb-server-node-tcp package provides two APIs for connecting to ADB Server using Node.js built-in net module:
Recommended: AdbServerNodeJsClient
A high-level wrapper class that extends AdbServerClient and handles connector creation automatically. This is the preferred approach for most applications.
Advanced: AdbServerClient with AdbServerNodeTcpConnector
Direct usage of the base client with explicit connector for advanced use cases requiring low-level control.
Both APIs share the same constructor overloads and support identical connection options and environment variables.
- npm
- Yarn
- pnpm
- Bun
npm i @yume-chan/adb-server-node-tcp
yarn add @yume-chan/adb-server-node-tcp
pnpm add @yume-chan/adb-server-node-tcp
bun add @yume-chan/adb-server-node-tcp
Constructor Overloads (Apply to Both APIs)
The following constructor overloads are available for both AdbServerNodeJsClient and AdbServerNodeTcpConnector:
Default Connection
Connects to the default socket spec using environment variables if set.
declare class AdbServerNodeTcpConnector {
constructor();
}
declare class AdbServerNodeJsClient extends AdbServerClient {
constructor();
}
If environment variable ADB_SERVER_SOCKET is set, it will be parsed as an ADB socket spec and used. Otherwise, a TCP socket spec is used, where the host is localhost or the value of the environment variable ANDROID_ADB_SERVER_ADDRESS, and the port is 5037 or the value of the environment variable ANDROID_ADB_SERVER_PORT.
# Set environment variables for server connection
export ADB_SERVER_SOCKET=tcp:localhost:5037
# or
export ANDROID_ADB_SERVER_ADDRESS=localhost
export ANDROID_ADB_SERVER_PORT=5037
# Then run adb commands normally
adb devices
- JavaScript
- TypeScript
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector = new AdbServerNodeTcpConnector();
// OR
const client = new AdbServerNodeJsClient();
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector();
// OR
const client: AdbServerNodeJsClient = new AdbServerNodeJsClient();
ADB Socket Spec String
Connects to the specified socket using an ADB socket spec string.
declare class AdbServerNodeTcpConnector {
constructor(spec: string);
}
declare class AdbServerNodeJsClient extends AdbServerClient {
constructor(spec: string);
}
Accepts an ADB socket spec string to define the connection.
TCP sockets:
"tcp:<host>": connects to the default TCP port on the specified host"tcp:<port>": connects to the specified TCP port on default host"tcp:<host>:<port>": connects to the specified port on the specified host
Unix domain sockets:
"local:<path>"or"localfilesystem:<path>": connects to the specified Unix domain socket on a file path. Not supported on Windows.
The default host is localhost, or the value of the environment variable ANDROID_ADB_SERVER_ADDRESS.
The default port is 5037, or the value of the environment variable ANDROID_ADB_SERVER_PORT.
vsock: and localabstract: socket specs are not supported.
# Using the -L flag to specify the socket
adb -L tcp:localhost:5037 devices
# Or set environment variable
export ADB_SERVER_SOCKET=tcp:localhost:5037
adb devices
- JavaScript
- TypeScript
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector = new AdbServerNodeTcpConnector("tcp:localhost:5037");
// OR
const client = new AdbServerNodeJsClient("tcp:localhost:5037");
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector("tcp:localhost:5037");
// OR
const client: AdbServerNodeJsClient = new AdbServerNodeJsClient("tcp:localhost:5037");
TCP Socket Options
Connects using specific TCP socket connection options.
declare class AdbServerNodeTcpConnector {
constructor(
spec: Omit<TcpSocketConnectOpts, "port"> & {
port?: number | undefined;
},
);
}
declare class AdbServerNodeJsClient extends AdbServerClient {
constructor(
spec: Omit<TcpSocketConnectOpts, "port"> & {
port?: number | undefined;
},
);
}
Uses the specified TCP connect options.
Unlike the original Node.js TCP connect options, the port field is also optional.
If both port and host fields are undefined, and environment variable ADB_SERVER_SOCKET is set, it will be parsed as an ADB socket spec and used. Otherwise, if the host field is undefined, the default value is localhost or the value of the environment variable ANDROID_ADB_SERVER_ADDRESS. If the port field is undefined, the default value is 5037 or the value of the environment variable ANDROID_ADB_SERVER_PORT.
# Using the -H and -P flags to specify host and port
adb -H localhost -P 5037 devices
# Or set environment variables
export ANDROID_ADB_SERVER_ADDRESS=localhost
export ANDROID_ADB_SERVER_PORT=5037
adb devices
- JavaScript
- TypeScript
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector = new AdbServerNodeTcpConnector({
host: "localhost",
port: 5037,
});
// OR
const client = new AdbServerNodeJsClient({
host: "localhost",
port: 5037,
});
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector({
host: "localhost",
port: 5037,
});
// OR
const client: AdbServerNodeJsClient = new AdbServerNodeJsClient({
host: "localhost",
port: 5037,
});
Unix Domain Socket
Connects using Node.js Unix domain socket connection options.
declare class AdbServerNodeTcpConnector {
constructor(spec: IpcSocketConnectOpts);
}
declare class AdbServerNodeJsClient extends AdbServerClient {
constructor(spec: IpcSocketConnectOpts);
}
Uses the specified Node.js domain socket connect options. Not supported on Windows, because ADB server can't listen on Named Pipes on Windows.
# Using the -L flag with local socket (Unix only)
adb -L local:/path/to/adb_socket devices
- JavaScript
- TypeScript
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector = new AdbServerNodeTcpConnector({
path: "/path/to/socket",
});
// OR
const client = new AdbServerNodeJsClient({
path: "/path/to/socket",
});
import { AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector({
path: "/path/to/socket",
});
// OR
const client: AdbServerNodeJsClient = new AdbServerNodeJsClient({
path: "/path/to/socket",
});
Usage Examples
Recommended: Use AdbServerNodeJsClient
For most Node.js use cases, the recommended approach is to use AdbServerNodeJsClient, which is a high-level wrapper that handles connector creation automatically.
- JavaScript
- TypeScript
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
// Recommended: Use the wrapper class directly
const client = new AdbServerNodeJsClient();
import { AdbServerNodeJsClient } from "@yume-chan/adb-server-node-tcp";
// Recommended: Use the wrapper class directly
const client: AdbServerNodeJsClient = new AdbServerNodeJsClient();
Advanced: Use AdbServerClient with connector
For advanced use cases requiring low-level control over the connection, you can still use AdbServerClient with AdbServerNodeTcpConnector directly.
- JavaScript
- TypeScript
import { AdbServerClient, AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
// Advanced: Use the connector directly for low-level control
const connector = new AdbServerNodeTcpConnector({
host: "localhost",
port: 5037,
});
const client = new AdbServerClient(connector);
import { AdbServerClient, AdbServerNodeTcpConnector } from "@yume-chan/adb-server-node-tcp";
// Advanced: Use the connector directly for low-level control
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector({
host: "localhost",
port: 5037,
});
const client: AdbServerClient = new AdbServerClient(connector);
Use this approach only when you need:
- Custom connection pooling
- Advanced error handling
- Direct socket manipulation
- Integration with other connection management systems
Create client
With a server connector, we can create a client:
- JavaScript
- TypeScript
import { AdbServerClient } from "@yume-chan/adb";
const client = new AdbServerClient(connector);
import { AdbServerClient } from "@yume-chan/adb";
const client: AdbServerClient = new AdbServerClient(connector);
This step doesn't send or receive any packets, it only initializes some internal states.