Connect with the TypeScript client
Learn how to connect to a Serverless (Vector) database with the astra-db-ts client.
Prerequisites
-
An active Astra account
-
An active Serverless (Vector) database
-
An application token with the Database Administrator role
Install the TypeScript client
Install the TypeScript client:
-
Verify that Node is version 18 or higher.
node --version
-
Install the TypeScript client with your preferred package manager:
-
npm
-
Yarn
-
pnpm
npm install @datastax/astra-db-ts
yarn add @datastax/astra-db-ts
pnpm add @datastax/astra-db-ts
-
Connect to a vector-enabled Astra DB Serverless database
Create a file named quickstart.ts
.
quickstart.ts
import { DataAPIClient, VectorDoc, UUID } from '@datastax/astra-db-ts';
const { ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT } = process.env;
// Initialize the client and get a "Db" object
const client = new DataAPIClient(ASTRA_DB_APPLICATION_TOKEN);
const db = client.db(ASTRA_DB_API_ENDPOINT);
console.log(* Connected to DB ${db.id}
);