Connect the Node.js driver to your database
This driver supports the vector and non-vector data types. DataStax recommends the Data API and clients for Serverless (Vector) databases. You can use the Data API to perform CQL operations on your table data in Serverless (Vector) databases. DataStax recommends drivers only for Serverless (Non-Vector) databases, existing applications that previously used a CQL-based driver, or if you need to use some CQL functions that aren’t supported by the Data API. For more information, see Connection methods comparison. |
Initialize the Node.js driver to connect to your database.
Prerequisites
-
Download your database’s Secure Connect Bundle (SCB).
Connect
This code configures the Node.js driver with an SCB and authentication details, then establishes a connection to the database through an asynchronous run function.
const cassandra = require('cassandra-driver');
const cloud = { secureConnectBundle: process.env['ASTRA_DB_SECURE_BUNDLE_PATH'] };
const authProvider = new cassandra.auth.PlainTextAuthProvider('token', process.env['ASTRA_DB_APPLICATION_TOKEN']);
const client = new cassandra.Client({ cloud, authProvider });
async function run() {
await client.connect();
// ...
}
See the Node.js quickstart for details on how to install the package, connect to a Serverless (Vector) database, create a table and vector-compatible SAI (Storage-Attached Index), load data, and perform a similarity search.