Migrating your DataStax Node.js driver to connect with Astra databases

Migrate your existing DataStax Node.js driver to a version compatible with Cassandra databases.

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

Prerequisites

  1. Create a DataStax Astra database.
  2. Download the secure connect bundle to obtain connection credentials for your DataStax Astra database.

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
  2. In your existing DataStax Node.js driver code, modify the connection code to use the DataStax Astra 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: 'username', password: 'password' }
        });
      
    • DSE Node.js driver

      const dse = require('dse-driver');
      
      const client = new Client({
          cloud: { secureConnectBundle: 'path/to/secure-connect-database_name.zip' },
          credentials: { username: 'username', password: 'password' }
        });
      
  3. Run your Node.js script to connect to your Astra database.
    node my_node.js_driver.js

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