Skip to content

Data Server

The data server provides network access to a server-side DuckDB instance from Node.js. Both WebSocket (socket) and HTTP (rest) connections are supported.

WARNING

Due to persistent quality issues involving the DuckDB Node.js client and Arrow extension, we recommend using Mosaic's Python-based duckdb-server package instead. However, we retain this JavaScript-based server for both backwards compatibility and potential future use as quality issues improve.

dataServer

dataServer(db, options)

Launch a new data server instance. The db argument should be a DuckDB instance.

The following options are supported:

  • port: The port number (default 3000) on which to listen for query requests.
  • rest: Boolean flag (default true) indicating if HTTP REST connections should be enabled.
  • socket: Boolean flag (default true) indicating if WebSocket connections should be enabled.

Once launched, the data server will accept HTTP POST requests containing JSON content that consists of a single object with the following properties:

  • type: The type of query (required). The type "exec" indicates that the provided query should be run with no return value. The "arrow" type indicates that the result table should be returned as Arrow IPC bytes.
  • sql: The SQL query string to issue to DuckDB.

A request without a type is rejected with HTTP status 400.

Examples

Launch a data server in Node.js:

js
import { DuckDB, dataServer } from "@uwdata/mosaic-duckdb";
dataServer(new DuckDB(), { rest: true, socket: true });