backedn converted to ts
This commit is contained in:
+11
-10
@@ -1,20 +1,21 @@
|
||||
const mongoose = require('mongoose');
|
||||
const config = require('config');
|
||||
import mongoose from "mongoose";
|
||||
import config from 'config'
|
||||
|
||||
const db = config.get('mongoURI');
|
||||
|
||||
const connectDB = async () => {
|
||||
try {
|
||||
await mongoose.connect(db, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true
|
||||
});
|
||||
if (typeof db === 'string')
|
||||
await mongoose.connect(db);
|
||||
|
||||
console.log('MongoDB Connected...');
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
// Exit process with failure
|
||||
} catch (err: unknown) {
|
||||
if (typeof err === 'string')
|
||||
console.error(err)
|
||||
else if (err instanceof Error)
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = connectDB;
|
||||
export default connectDB
|
||||
|
||||
Reference in New Issue
Block a user