# RPC (/sdks/nodejs/reference/rpc)



Commands and queries share message factories (`createCommand`, `createQuery`). Responses are strongly typed `CommandResponse` / `QueryResponse` objects.

## Commands [#commands]

### sendCommand [#sendcommand]

```typescript
const response = await client.sendCommand(command: CommandMessage): Promise<CommandResponse>
```

**CommandMessage** (via `createCommand()`):

| Field              | Type                     | Required    | Description    |
| ------------------ | ------------------------ | ----------- | -------------- |
| `channel`          | `string`                 | Yes         | Target channel |
| `body`             | `string \| Uint8Array`   | Conditional | Payload        |
| `metadata`         | `string`                 | Conditional | Metadata       |
| `timeoutInSeconds` | `number`                 | Yes         | RPC timeout    |
| `tags`             | `Record<string, string>` | No          | Tags           |

### subscribeToCommands [#subscribetocommands]

```typescript
client.subscribeToCommands(subscription: CommandSubscription): Subscription
```

### sendCommandResponse [#sendcommandresponse]

```typescript
await client.sendCommandResponse(response: CommandResponse): Promise<void>
```

## Queries [#queries]

### sendQuery [#sendquery]

```typescript
const response = await client.sendQuery(query: QueryMessage): Promise<QueryResponse>
```

**QueryMessage** (via `createQuery()`) extends command fields with:

| Field               | Type     | Description |
| ------------------- | -------- | ----------- |
| `cacheKey`          | `string` | Cache key   |
| `cacheTtlInSeconds` | `number` | TTL seconds |

### subscribeToQueries [#subscribetoqueries]

```typescript
client.subscribeToQueries(subscription: QuerySubscription): Subscription
```

### sendQueryResponse [#sendqueryresponse]

```typescript
await client.sendQueryResponse(response: QueryResponse): Promise<void>
```

## Quick Usage [#quick-usage]

```typescript title="rpc.ts"
const response = await client.sendCommand(
  createCommand({
    channel: "svc.commands",
    body: Buffer.from("ping"),
    timeoutInSeconds: 5,
  }),
);
```

## See Also [#see-also]

* [RPC Examples](/sdks/nodejs/how-to/rpc/)
* [RPC pattern](/learn/rpc/getting-started)
* [Node.js SDK Getting Started](/sdks/nodejs)
