setting up dotenv and stuff

This commit is contained in:
talksik
2022-04-01 11:46:08 -04:00
parent 8a1163dc3f
commit ce0fb7a885
9 changed files with 101 additions and 263 deletions
+5 -7
View File
@@ -1,18 +1,19 @@
// External Dependencies
import * as mongoDB from "mongodb";
// import * as dotenv from "dotenv";
import { loadConfig } from "../config";
// Global Variables
export const collections: {
users?: mongoDB.Collection;
relationships?: mongoDB.Collection;
} = {};
// Initialize Connection
export async function connectToDatabase() {
const config = loadConfig();
const client: mongoDB.MongoClient = new mongoDB.MongoClient(
"mongodb+srv://default:[email protected]/default?retryWrites=true&w=majority"
config.MONGO_CONNECTION_STRING
);
await client.connect();
@@ -20,11 +21,8 @@ export async function connectToDatabase() {
const db: mongoDB.Db = client.db(process.env.DB_NAME);
const usersCollection: mongoDB.Collection = db.collection("users");
const relationshipCollection: mongoDB.Collection =
db.collection("relationships");
collections.users = usersCollection;
collections.relationships = relationshipCollection;
console.log(
`Successfully connected to database: ${db.databaseName} and collections`