5a8fccd190 | ||
---|---|---|
.vscode | ||
samples | ||
src | ||
.editorConfig | ||
.gitattributes | ||
.gitignore | ||
.npmignore | ||
.prettierrc.json | ||
.travis.yml | ||
Contributing.md | ||
LICENSE | ||
README.md | ||
SDK + Samples Workspace.code-workspace | ||
browser-test.js | ||
changelog.md | ||
dev.md | ||
karma.config.js | ||
package-lock.json | ||
package.json | ||
tsconfig.json | ||
tslint.json | ||
webpack.config.js |
README.md
Microsoft Azure Cosmos JavaScript SDK
This project provides JavaScript & Node.js SDK library for SQL API of Azure Cosmos Database Service. This project also includes samples, tools, and utilities.
import { CosmosClient } from "@azure/cosmos"
const endpoint = "[hostendpoint]"; // Add your endpoint
const masterKey = "[database account masterkey]"; // Add the masterkey of the endpoint
const client = new CosmosClient({endpoint, auth: { masterKey }});
const databaseDefinition = { id: "sample database" };
const collectionDefinition = { id: "sample collection" };
const itemDefinition = { id: "hello world doc", content: "Hello World!" };
async function helloCosmos() {
const { database: db } = await client.database.create(databaseDefinition);
console.log('created db');
const { container } = await db.container.create(collectionDefinition);
console.log('created collection');
const { body } = await container.items.create(documentDefinition);
console.log('Created item with content: ', body.content);
await db.delete();
console.log("Deleted database");
});
helloCosmos().catch((err)=>{console.error(err)});
Useful links
- Welcome to Azure Cosmos DB
- Quick start
- Tutorial
- Samples
- Introduction to Resource Model of Azure Cosmos DB Service
- Introduction to SQL API of Azure Cosmos DB Service
- Partitioning
- API Documentation
Installation
Prerequisites
Install Node.js 6 or above and npm https://docs.npmjs.com/getting-started/installing-node
The SDK is not supported in Node v4 or below. Those Node.js versions are out of support and not recommended for production. Our support will only cover maintained versions of Node.js.
To use the SDK, first create an account and follow tutorial.
Note:
When connecting to the emulator from the SDK, SSL verification is disabled.
Follow these instructions to run the tests locally.
Install
npm install @azure/cosmos
Tests
Prerequisites
-
Clone Azure/azure-cosmos-js repository
git clone https://github.com/azure/azure-cosmos-js.git
-
Install Node.js 6 or above and npm https://docs.npmjs.com/getting-started/installing-node
-
- Note: requires a windows machine or ability to run Windows container
-
Install dependencies
npm i # alias for npm install
-
Build the source
npm run build # compiles the typescript source, runs linting, creates webpack, creates docs
Running the tests
npm run test # runs all tests
Need Help?
Tweet us with #CosmosDB and we'll respond on Twitter. Be sure to check out the Microsoft Azure Developer Forums on MSDN or the Developer Forums on Stack Overflow if you have trouble with the provided code.
Contribute Code or Provide Feedback
If you would like to become an active contributor to this project please follow the instructions provided in Azure Projects Contribution Guidelines.
If you encounter any bugs with the library please file an issue in the Issues section of the project.