Migrate Node.js driver

Complete the following procedure to migrate your existing DataStax Node.js driver to a version that is capable of connecting to Astra DB databases created using DataStax Astra DB.

Prerequisites

Procedure

  1. Install the DataStax Node.js driver:

DataStax Node.js driver for Apache Cassandra

npm install cassandra-driver

DSE driver

npm install dse-driver
  1. In your existing DataStax Node.js driver code, modify the connection code to use the Astra DB API. Include the absolute path to the secure connect bundle for your Cassandra database (secure-connect-database_name.zip) in the secureConnectBundle parameter, as shown in the following examples.

DataStax Node.js driver for Apache Cassandra

const { Client } = require('cassandra-driver');
const client = new Client({
    cloud: { secureConnectBundle: 'path/to/secure-connect-database_name.zip' },
    credentials: { username: 'clientId', password: 'clientSecret' }
  });

===DSE Node.js driver

const dse = require('dse-driver');

const client = new Client({
    cloud: { secureConnectBundle: 'path/to/secure-connect-database_name.zip' },
    credentials: { username: 'clientId', password: 'clientSecret' }
  });
  1. Run your Node.js script to connect to your Astra DB database:

node my_node.js_driver.js

If successful, the code builds, compiles, and connects to your Cassandra database.