rsnext/examples/with-azure-cosmos
2024-05-08 21:47:14 +02:00
..
lib chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07:00
pages chore: update prettier to 3.2.5 (#65092) 2024-05-08 21:47:14 +02:00
public Added Azure Cosmos DB started code, containing a minimal app and README.md (#49128) 2023-06-08 21:42:46 +00:00
.env.local.example Added Azure Cosmos DB started code, containing a minimal app and README.md (#49128) 2023-06-08 21:42:46 +00:00
.gitignore Add .yarn/install-state.gz to .gitignore (#56637) 2023-10-18 16:34:48 +00:00
package.json Added Azure Cosmos DB started code, containing a minimal app and README.md (#49128) 2023-06-08 21:42:46 +00:00
README.md Added Azure Cosmos DB started code, containing a minimal app and README.md (#49128) 2023-06-08 21:42:46 +00:00
tsconfig.json Added Azure Cosmos DB started code, containing a minimal app and README.md (#49128) 2023-06-08 21:42:46 +00:00

Example app using Azure Cosmos DB

Azure Cosmos DB is a fully managed NoSQL and relational database for modern app development. Azure Cosmos DB offers single-digit millisecond response times, automatic and instant scalability, along with guarantee speed at any scale. Business continuity is assured with SLA-backed availability and enterprise-grade security.

Deploy your own

Once you have access to the environment variables you'll need, deploy the example using Vercel:

Deploy with Vercel

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app --example with-azure-cosmos with-azure-cosmos-app
yarn create next-app --example with-azure-cosmos with-azure-cosmos-app
pnpm create next-app --example with-azure-cosmos with-azure-cosmos-app

Configuration

Set up a Azure Cosmos DB database

Set up a CosmosDB database with Try Azure Cosmos DB free.

Set up environment variables

Copy the env.local.example file in this directory to .env.local (which will be ignored by Git):

cp .env.local.example .env.local

Set each variable on .env.local:

  • COSMOSDB_CONNECTION_STRING - You will need your Cosmos DB connection string. You can find these in the Azure Portal in keys section.
  • COSMOSDB_DATABASE_NAME - Name of the database you plan on using. This should already exist in the Cosmos DB account.
  • COSMOSDB_CONTAINER_NAME - Name of the container you plan on using. This should already exist in the previous database.

Run Next.js in development mode

npm install
npm run dev

# or

yarn install
yarn dev

Your app should be up and running on http://localhost:3000! If it doesn't work, post on GitHub discussions.

You will either see a message stating "You are connected to CosmosDB" or "You are NOT connected to CosmosDB". Please make sure you have provided valid environment variables.

When you are successfully connected, you can refer to the Azure Cosmos DB client library for JavaScript/TypeScript for further instructions on how to query your database.

Deploy on Vercel

You can deploy this app to the cloud with Vercel (Documentation).