Skip to content

Commit

Permalink
move mongo hostname and port to envvars
Browse files Browse the repository at this point in the history
  • Loading branch information
aidengaripoli committed Nov 13, 2018
1 parent 5eda7b4 commit 646d499
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ services:
- NODE_ENV=development
- MONGO_USERNAME=root
- MONGO_PASSWORD=example
- MONGO_HOSTNAME=mongo
- MONGO_PORT=27017
- MONGO_DATABASE_NAME=example-database
depends_on:
mongo:
Expand Down
2 changes: 2 additions & 0 deletions docker-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
- NODE_ENV=production
- MONGO_USERNAME_FILE=/run/secrets/mongo_root
- MONGO_PASSWORD_FILE=/run/secrets/mongo_root_password
- MONGO_HOSTNAME=mongo
- MONGO_PORT=27017
- MONGO_DATABASE_NAME=example-database
secrets:
- mongo_root
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const MongoClient = require('mongodb').MongoClient;
const {
MONGO_USERNAME,
MONGO_PASSWORD,
MONGO_HOSTNAME,
MONGO_PORT,
MONGO_DATABASE_NAME
} = process.env;

// Connection URL
const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@mongo:27017`;
const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}`;

// Create a new MongoClient
const client = new MongoClient(url);
Expand Down

0 comments on commit 646d499

Please sign in to comment.