This sample shows you how to use the Microsoft Azure Cosmos DB with its DocumentDB API to store and access data from a Node.js Express application. It is based on the original sample available here, but has been rewritten in ES6 and updated to use Application Insights and dotenv. The project is set up to be used with Visual Studio Code and ESLint. Please make sureto have ESLint installed globally (npm i -g eslint eslint-config-defaults
).
In order to run the sample locally, create a text file called .env
in the project's root directory and add the environment settings HOST
, AUTH_KEY
, and APPINSIGHTS_INSTRUMENTATIONKEY
(see the dotenv documentation to understand the file format).
Note that .env
is included in the project's .gitignore
and thus will not be commited to your git repo in order to protect your Cosmos DB and Application Insights keys.
The project also contains a basic Dockerfile to get you started to build a containerized version of this app. Just follow these instructions, and don't forget to supply HOST, AUTH_KEY, and APPINSIGHTS_INSTRUMENTATIONKEY as environment. You can reuse the aforementioned .env
file for this purpose by adding --env-file .env
as parameter to docker run
, e.g. docker run -d -p 3000:3000 --env-file .env --name "todo-app" <image-name>
(replace the host port or container name as desired).
A prebuilt Docker image of this app is available on Docker Hub. This
image is built automatically from this repository, so if you run it, make sure to pass your Cosmos DB and Application Insight settings
as environment (see above), or map a volume containing an .env
file.