@azure/cosmos has moved to a new repo https://github.com/Azure/azure-sdk-for-js
Перейти к файлу
Steve Faulkner 0e1a03cbda 3.0.0-8 2019-03-21 23:05:26 -07:00
.vscode Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
consumer-test Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
samples Add change feed support (#196) 2018-12-03 11:56:33 -08:00
src Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
test Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
.editorConfig Match EditorConfig with Prettier rules (#165) 2018-10-26 10:40:46 -06:00
.gitattributes adding .git* 2014-08-26 08:25:08 -07:00
.gitignore Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
.npmignore ES module interop fixes; use rollup for production builds (#104) 2018-12-14 08:12:55 -05:00
.prettierignore Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
.prettierrc.json Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
.travis.yml TS Consumer Smoke Test (#199) 2018-11-30 15:13:40 -05: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 Preferred locations are now properly honored + dev docs improvements (#181) 2018-11-06 21:50:13 -08:00
SDK + Samples Workspace.code-workspace TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
api-extractor.json Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
browser-test.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
bundle-types.js ES module interop fixes; use rollup for production builds (#104) 2018-12-14 08:12:55 -05:00
changelog.md 2.0.1 (#143) 2018-09-24 18:26:17 -07:00
consumer-test.js Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
dev.md Add multiregion guard for change feed tests (#209) 2018-12-13 13:19:06 -08:00
karma.config.js TypeScript conversion (#3) 2018-06-04 14:03:49 -07:00
package-lock.json 3.0.0-8 2019-03-21 23:05:26 -07:00
package.json 3.0.0-8 2019-03-21 23:05:26 -07:00
rollup.config.js Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
tsconfig.json Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -07:00
tslint.json Enable no-unecessary-class (v3) (#211) 2018-12-18 20:25:59 -05:00
writeSDKVersion.js Convert to TS project references. Extract test folder (#270) 2019-03-19 10:29:27 -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 Build Status Build Status

// 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);
});

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

For our rules and guidelines on contributing, please see [Microsoft's contributor guide].(https://docs.microsoft.com/en-us/contribute/).

For information on how build and test this repo, please see ./dev.md.

If you encounter any bugs with the library please file an issue in the Issues section of the project.