Giter Site home page Giter Site logo

bterlson / azure-cosmos-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure/azure-cosmos-js

0.0 2.0 0.0 10.25 MB

JavaScript and Node.js library for Azure Cosmos DB

Home Page: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-nodejs-get-started-preview

License: MIT License

JavaScript 0.37% TypeScript 99.63%

azure-cosmos-js's Introduction

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

Useful links

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.

azure-cosmos-js's People

Contributors

1n50mn14 avatar a8m avatar aliuy avatar ato9000 avatar bchong95 avatar bterlson avatar bursteg avatar dmitriykirakosyan avatar dwhieb avatar fkollmann avatar igorklopov avatar joaomoreno avatar johnpapa avatar kapil-ms avatar khdang avatar kirankumarkolli avatar lmaccherone avatar matiassingers avatar moderakh avatar molant avatar nomiero avatar pacific202 avatar peterblazejewicz avatar rnagpal avatar ronaldewatts avatar ryancrawcour avatar shipunyc avatar southpolesteve avatar ytechie avatar ziyel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.