# Ping (/sdks/nodejs/how-to/connection/ping)



## Overview [#overview]

A ping is a lightweight liveness check — you call it to confirm the broker is actually reachable before sending real traffic, without standing up a publisher, subscriber, or queue client just to find out. It's the tool of choice for startup readiness checks, container liveness/readiness probes, and connection-health dashboards that need a fast, cheap go/no-go signal.

`client.ping()` issues a minimal gRPC `Ping` request to the server and returns a `ServerInfo` object (`host`, `version`, `serverUpTime`) confirming the broker answered. It works over the same connection regardless of which messaging pattern you use elsewhere on that client — events, queues, commands, or queries.

**Gotchas:** a failed `ping()` doesn't close the client — the SDK's reconnect logic keeps retrying in the background, so catch the thrown error yourself (`err.code`) rather than assume the client tears itself down. A successful ping only confirms the broker process answered, not that a specific channel or queue exists or has capacity. And `ping()` is on-demand — it's not called automatically by `KubeMQClient.create()`, so a client can construct successfully yet still be unable to reach the broker.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Node.js SDK installed (`npm install kubemq-js`)

## Code [#code]

```typescript title="ping.ts"
import { KubeMQClient } from 'kubemq-js';

async function main() {
  const client = await KubeMQClient.create({
    address: 'localhost:50000',
    clientId: 'js-connection-ping-client',
  });

  try {
    const info = await client.ping();
    console.log('Server host:', info.host);
    console.log('Server version:', info.version);
    console.log('Uptime (s):', info.serverUpTime);
  } finally {
    await client.close();
  }
}

main().catch(console.error);

```

## How It Works [#how-it-works]

* `client.ping()` sends a gRPC `Ping` request and returns a `ServerInfo` object with `host`, `version`, and `serverUpTime` — the call fails fast with `KubeMQTimeoutError` if the server is unreachable.
* Unlike `KubeMQClient.create()`, `ping()` is an explicit on-demand health check; use it in readiness probes or before batch operations to confirm connectivity.
* The `serverUpTime` field is in seconds since the server process started and can be used to detect recent restarts.
* If `ping()` throws, inspect `err.code` — `ConnectionTimeout` means no response, `AuthFailed` means credentials are rejected.

## Related [#related]

* [Node.js SDK Reference](/sdks/nodejs/reference)
* [Connect](/sdks/nodejs/tutorials/connect)
* [Close](/sdks/nodejs/how-to/connection/close)
