summary refs log tree commit diff
path: root/src/db/db.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/db.js')
-rw-r--r--src/db/db.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/db/db.js b/src/db/db.js
new file mode 100644

index 0000000..bf7ccfa --- /dev/null +++ b/src/db/db.js
@@ -0,0 +1,16 @@ +import { connect } from "mongoose"; + +export async function initDb() { + const connStr = "mongodb://root:Foxy1987@localhost/myproject"; + try { + const res = await connect(connStr); + if (res.connection.readyState === 1) { + console.log("[MONGODB] Connected successfully!"); + } else { + console.error("[MONGODB] Failed to connect to ", connStr); + } + } catch (e) { + console.error("[MONGODB] Error connecting to database!"); + throw e; + } +}