Last active
December 25, 2021 07:57
-
-
Save neerajkumar161/23e1008b9423b0191e283e249a17fc1a to your computer and use it in GitHub Desktop.
db/mongodb.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import config from 'config' | |
import {connect} from 'mongoose' // import connect method from mongoose | |
const MONGO_URI: string = config.get('db_url') // This will get the db_url, that we've declared in config/default.json file | |
export const connectMongoDB = async () => { | |
try { | |
const res = await connect(MONGO_URI) | |
if (res) console.log('Connected to MongoDB') | |
} catch (error) { | |
console.log('MongoDB connection error', error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment