Connect with the TypeScript client
Learn how to connect to a Serverless (Vector) database with the astra-db-ts client.
Prerequisites
-
You have an active Astra account
-
You have created a Serverless (Vector) database.
-
You have generated an application token with the Database Administrator role.
-
You have installed Node 14 or higher.
Install the TypeScript client
-
Verify that Node is version 14 or higher.
node --version
-
Use npm or Yarn to install the client.
-
npm
-
Yarn
To install the TypeScript client with npm:
npm install @datastax/astra-db-ts
To install the TypeScript client with Yarn:
-
Verify that Yarn is version 2.0 or higher.
yarn --version
-
Install the
astra-db-ts
package.yarn add @datastax/astra-db-ts
-
Connect to a vector-enabled Astra DB Serverless database
Create a file named 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}
);
Next steps
-
See a complete TypeScript example of how to connect to a database, load data into a collection, and perform a similarity search.
-
Read the TypeScript client reference for more details about available methods.
-
Also see the TypeScript tab for details and examples in each task-based section of the API Reference topics: