The Guide for Time Series Data Projects is out.

Download now
Skip to content

How to Connect with Node.js

Effortlessly connect to CrateDB with Node.js through the node-postgres collection.


Connecting to CrateDB with Node.js is made effortless through the node-postgres collection, providing extensive functionalities for seamless integration between Node.js applications and CrateDB databases. This module supports various programming paradigms and rich capabilities, facilitating efficient communication and interaction tailored for Node.js environments and CrateDB.

There are two primary Node.js modules and drivers available for connecting to CrateDB. These modules offer distinct approaches for Node.js developers to interface with CrateDB, each with unique features and functionalities.


const { Client } = require("pg");

const crateClient = new Client({
  host: "",
  port: 5432,
  user: "admin",
  password: "",
  ssl: true,

(async () => {
  await crateClient.connect();
  const result = await crateClient.query("SELECT name FROM sys.cluster");

const crate = require("node-crate");


(async () => {
  const result = await crate.execute("SELECT name FROM sys.cluster");

The node-postgres collection enables smooth interaction between Node.js applications and CrateDB databases. With comprehensive functionalities, including support for various programming paradigms (callbacks, promises, async/await), connection pooling, prepared statements, cursors, and streaming results, developers experience seamless integration when interfacing Node.js with CrateDB. For detailed insights and setup guidance, refer to the node-postgres documentation, empowering efficient utilization of CrateDB's full potential within Node.js applications.

The node-crate Node.js independent driver offers a tailored approach specifically designed for CRATE. Leveraging the _sql endpoint REST API, this alternative implementation provides developers with an additional option for establishing connections and interactions with CrateDB, catering to diverse development preferences and scenarios. Explore the node-crate driver documentation

Additional resources