What is your rating of GIT Belgaum

Quick start: Build a Cassandra app with the Node.js SDK and Azure Cosmos DB

  • 6 minutes to read


In this quickstart, you'll create an Azure Cosmos DB Cassandra API account and use a GitHub cloned Cassandra-Node.js app to create a Cassandra database and container. Azure Cosmos DB is a multi-model database service that enables you to quickly create and query document, table, key-value, and graph databases using global distribution and scale-out capabilities.


If you don't have an Azure subscription, create a free account before you begin. Alternatively, you can try Azure Cosmos DB without an Azure subscription - free of charge and with no obligation.

You also need:

Create a database account

Before creating a document database, you must create a Cassandra account using Azure Cosmos DB.

  1. Sign in to the Azure portal in a new browser window.

  2. Select in the menu on the left Create resource out.

  3. Select on the side New the options Databases > Azure Cosmos DB out.

  4. Enter on the side Create an Azure Cosmos DB account Enter the settings for the new Azure Cosmos DB account:

    SubscriptionYour subscriptionSelect the Azure subscription that you want to use for this Azure Cosmos DB account.
    Resource groupCreate new

    Then enter the same name as the account name.
    Choose Create new. Then enter a new resource group name for your account. For simplicity, use the same name as the Azure Cosmos account name.
    Account nameEnter a unique name.Enter a unique name that identifies your Azure Cosmos DB account. The account URI is cassandra.cosmos.azure.com and is appended to your unique account name.

    The account name can only contain lowercase letters, numbers, and hyphens (-) and must be between 3 and 31 characters long.
    APICassandraThe API determines the type of account to be created. Azure Cosmos DB provides five APIs: Core API (SQL) for Document Databases, Gremlin API for Graph Databases, MongoDB API for Document Databases, Azure Tables API, and Cassandra API. You need to create a separate account for each API.

    Choose Cassandra because in this quickstart you will create a table that can be used with the Cassandra API.

    More information about the Cassandra API
    positionSelect the region that is closest to your users.Select a geographic location to host your Azure Cosmos DB account. Use a location that is closest to your users for quick access to the data.
    Capacity modeProvisioned throughput or serverlessChoose Provisioned Throughput to create an account in Provisioned Throughput mode. Choose Serverless to create an account in Serverless mode.

    Choose Rate + create out. You can use the sections network, Fuse, Encryption and Tags skip.

  5. It takes a few minutes to create an account. Wait for the portal to open the page Congratulations! Your Azure Cosmos DB account has been created is shown.

Cloning the sample application

In this step, we clone a Cassandra API app from GitHub, set the connection string, and run the app. You'll find how easy it is to work with data programmatically.

  1. Open a command prompt. Create a new folder called. Then close the command prompt.

  2. Open a Git terminal window, e.g. git bash. Use the command to switch to the new folder to install the sample app.

  3. Run the following command to clone the sample repository. This command makes a copy of the sample app on your computer.

  4. Install the Node.js dependencies with npm.

Check the code

This step is optional. If you want to learn how the code creates the database resources, you can take a look at the following code snippets. The code snippets are all taken from the file in the folder. Otherwise, you can proceed to updating the connection string.

  • The username and password values ​​were set on the Connection String page of the Azure portal.

  • is initialized with contactPoint information. The contactPoint is obtained from the Azure portal.

  • connects to the Azure Cosmos DB Cassandra API.

  • A new keyspace is created.

  • A new table is created.

  • Key-value entities are inserted.

  • Query to get all key values.

  • Query to get a key value.

  • Close the connection.

Update the connection string

Now switch back to the Azure portal to get the connection string information and copy it into the app. Specifying the connection string enables your app to communicate with your hosted database.

  1. In your Azure Cosmos DB account in the Azure portal, select Connection string out.

  2. Use the button on the right side of the screen to copy the top value (the contact point).

  3. Open the file.

  4. On line 9, replace with the contact point value from the portal.

    Line 9 should now look something like this:

  5. Copy the username value from the portal and overwrite it in line 2.

    Line 2 should now look something like this:

  6. Copy the value for the password from the portal and overwrite it on line 8.

    Line 8 should now look something like this:

  7. Replace REGION with the Azure region in which you created this resource.

  8. Save the file.

Run the Node.js app

  1. In the Terminal window, make sure you are in the samples directory that you cloned earlier:

  2. Run your Node application:

  3. Check the results from the command line.

    Press CTRL + C to end the program and close the console window.

  4. In the Azure portal, open the Data explorerto query, modify, and use this new data.

Review SLAs in the Azure portal

The Azure portal monitors throughput, storage, availability, latency and consistency of your Cosmos DB account. Azure Cosmos DB Service Level Agreement (SLA) metrics graphs show the SLA versus actual performance. This collection of metrics makes the monitoring of your SLAs transparent.

To review metrics and SLAs:

  1. From the navigation menu of your Cosmos DB account, select the option Metric out.

  2. Select a tab (such as waiting period) and select a time period on the right. Compare lines Indeed and SLA in the diagrams.

  3. Review the metrics on the other tabs.

Cleaning up resources

When you have completed your app and the Azure Cosmos DB account, you can delete the Azure resources that you created so that there are no further charges. To delete the resources:

  1. Search using the Azure portal search bar Resource groupsand select the appropriate option.

  2. From the list, select the resource group that you created for this quickstart.

  3. Select on the side Overview the resource group option Delete resource group out.

  4. In the next window, enter the name of the resource group to be deleted, then select Clear out.

Next Steps

In this quick start guide, you learned how to create an Azure Cosmos DB account with Cassandra API and run a Cassandra-Node.js app that creates a Cassandra database and a Cassandra container. You are now ready to import additional data into your Azure Cosmos DB account.

Is this page helpful?