Contoso Air is a sample airline booking application with a Node.js based frontend with a CosmosDB database. Runs a nodejs server (Express v4.16) that stores customer booked flights in a CosmosDb database.
- Node v8.9.4 or later
- Azure CosmosDb
This project uses ES6, and has been tested with nodejs v8.9.4.
There is almost no front-end logic. Still, the application uses webpack to compile sass styles and bundle third parties js files. If you want to modify any front logic or style run npm run local:build.
In order to launch a local server on port 3000 (can be modified with environment variable PORT) run:
npm install
SET %COSMOS_DB_NAME%=<azure_web_site>
SET %COSMOS_DB_AUTH_KEY%=<cosmos_auth_key>
npm startThis will run locally the server and attach to the CosmosDb Endpoint using mongodb connection string.
This guide explains how to run the ContosoAir Node.js application locally using Docker and MongoDB.
Install the following tools:
- Docker
- Docker Compose
Verify installation:
docker --version
docker compose versionThe application runs with two containers:
ContosoAir
│
├── contoso-air-app (Node.js application)
└── contoso-mongo (MongoDB database)
The application connects to the database using:
mongodb://mongodb:27017/contosoair
(mongodb is the Docker service name)
-
Clone the Repository
git clone <repo-url> cd ContosoAir
-
Fix Package Version. Update
package.jsonif it contains a placeholder:"version": "#{VERSION_NUMBER}#"
Change it to:
"version": "1.0.0"
-
Configure MongoDB Connection. Update the database connection code to use an environment variable.
Example:
const connectionString = process.env.MONGO_URL || "mongodb://localhost:27017/contosoair"; mongoose.connect(connectionString);
-
Build and Start Containers. Run the following command from the project root:
docker compose up --build
This will start:
- Node.js application container
- MongoDB container
-
Access the Application. Open your browser and access the below url.
http://localhost:8081
-
View running containers
docker ps
-
View application logs
docker compose logs -f
-
Stop containers
docker compose down
-
Rebuild containers
docker compose up --build
-
Connect to the MongoDB container:
docker exec -it contoso-mongo mongosh -
Useful commands:
show dbs use contosoair show collections
To stop and remove containers. Database data will persist using Docker volumes.
docker compose downRun the entire stack with a single command.
docker compose up --buildThen access:
http://localhost:8081
The ContosoAir application will run locally with MongoDB using Docker.
