Use the ClickHouse Node.js client (@clickhouse/client)
mainThe @clickhouse/client package is designed exclusively for Node.js runtimes (including Next.js Node runtime API routes, React Server Components, and Server Actions).
Important: Do NOT use this package for browser components, Web Workers, Next.js Edge runtime, or Cloudflare Workers. For those environments, use @clickhouse/client-web instead.
Core API Methods
client.insert(): Use this to write rows to ClickHouse.client.query(): Use this to read data. You can process results using.json(),.text(), or.stream()on the returnedresultSet.client.command(): Use this for DDL and statements that do not return rows (e.g.,CREATE,DROP,TRUNCATE,ALTER, orSET).client.ping(): Performs a health check. It returns{ success, error? }and never throws on connection failure.client.exec(): Returns the raw response stream of an arbitrary statement (rarely needed for standard coding).
import { createClient } from '@clickhouse/client';
const client = createClient({ url: 'http://localhost:8123' });
// Example usage
await client.close();