@azure/cosmos has moved to a new repo https://github.com/Azure/azure-sdk-for-js
Перейти к файлу
Tim Reilly 82d03c9c2e console log database and collection deletion (#158) 2018-10-10 11:26:14 -04:00
.vscode Multi-Region Write support (#106) 2018-09-20 18:27:04 -07:00
samples console log database and collection deletion (#158) 2018-10-10 11:26:14 -04:00
src 2.0.2 (#146) 2018-10-10 10:40:33 -04:00
.editorConfig Added an editorConfig 2017-01-18 12:56:28 +01:00
.gitattributes adding .git* 2014-08-26 08:25:08 -07:00
.gitignore Feature/object model refactor (#26) 2018-06-29 16:51:57 -07:00
.npmignore Package info clean up (#12) 2018-06-29 14:27:23 -07:00
.prettierrc.json Add Prettier (#33) 2018-07-12 19:30:18 -04:00
.travis.yml Add Prettier (#33) 2018-07-12 19:30:18 -04:00
Contributing.md Node.js SDK Release 1.7.0 2016-04-26 13:21:42 -07:00
LICENSE TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
README.md 2.0.2 (#146) 2018-10-10 10:40:33 -04:00
SDK + Samples Workspace.code-workspace TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
browser-test.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
changelog.md 2.0.1 (#143) 2018-09-24 18:26:17 -07:00
dev.md TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
karma.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
package-lock.json Update package-lock.json 2018-09-24 08:06:37 -07:00
package.json 2.0.2 (#146) 2018-10-10 10:40:33 -04:00
tsconfig.json Resolve merge conflicts 2018-09-24 08:03:24 -07:00
tsconfig.prod.json Remove sourcemap from the bundle in webpack -p mode. Helps #61 (#114) 2018-09-11 14:32:55 -07:00
tslint.json Add Prettier (#33) 2018-07-12 19:30:18 -04:00
webpack.config.js Remove sourcemap from the bundle in webpack -p mode. Helps #61 (#114) 2018-09-11 14:32:55 -07:00

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.

latest npm badge

// JavaScript
const cosmos = require('@azure/cosmos');
const CosmosClient = cosmos.CosmosClient;

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 documentDefinition = { id: 'hello world doc', content: 'Hello World!' };

async function helloCosmos() {
  const { database: db } = await client.databases.create(databaseDefinition);
  console.log('created db');

  const { container } = await db.containers.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);
});

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

  1. Clone Azure/azure-cosmos-js repository

    git clone https://github.com/azure/azure-cosmos-js.git
    
  2. Install Node.js 6 or above and npm https://docs.npmjs.com/getting-started/installing-node

  3. Cosmos DB emulator

    • Note: requires a windows machine or ability to run Windows container
  4. Install dependencies

    npm i     # alias for npm install
    
  5. 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.