From 9c3c6c6363f18f8d5a0f020fe5877e783a54b260 Mon Sep 17 00:00:00 2001 From: Devin Deng Date: Sun, 6 Nov 2022 17:14:23 -0800 Subject: [PATCH] use port env variable for mongodb client --- lib/getMongoDBClient.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/getMongoDBClient.ts b/lib/getMongoDBClient.ts index f72b04b..79249f5 100644 --- a/lib/getMongoDBClient.ts +++ b/lib/getMongoDBClient.ts @@ -3,10 +3,11 @@ import { Db, MongoClient } from 'mongodb'; const USERNAME = process.env.MONGO_USERNAME const PASSWORD = process.env.MONGO_PASSWORD const HOSTNAME = process.env.MONGO_HOSTNAME -const DATABASENAME = process.env.MONGO_DATABASE_NAME +const DATABASE_NAME = process.env.MONGO_DATABASE_NAME +const DATABASE_PORT = process.env.MONGO_DATABASE_PORT const URI = - `mongodb://${USERNAME}:${PASSWORD}@${HOSTNAME ?? 'localhost'}:3001`; + `mongodb://${USERNAME}:${PASSWORD}@${HOSTNAME ?? 'localhost'}:${DATABASE_PORT}`; let db: Db | null = null; @@ -18,7 +19,7 @@ export const getMongoDBClient = async () => { const client = new MongoClient(URI); await client.connect(); - db = client.db(DATABASENAME); + db = client.db(DATABASE_NAME); return db; }