Introducing Flights: agent-native data pipelines in MotherDuckJoin the livestream

Skip to main content

Node.js

The DuckDB Node.js client can connect to MotherDuck with an md: connection string, so JavaScript and TypeScript applications can query MotherDuck directly.

How it works with MotherDuck

  1. Install the DuckDB Node.js client in your application.
  2. Create a MotherDuck access token and provide it through a connection string parameter or environment variable.
  3. Open an md: connection and run SQL from your application code.

Example

import duckdb from '@duckdb/node-api';

const token = process.env.motherduck_token;
const instance = await duckdb.DuckDBInstance.create(`md:my_db?motherduck_token=${token}`);
const connection = await instance.connect();
const result = await connection.run('SELECT current_database()');