Skip to content

Instantly share code, notes, and snippets.

@neerajkumar161
Last active December 25, 2021 07:57
Show Gist options
  • Save neerajkumar161/23e1008b9423b0191e283e249a17fc1a to your computer and use it in GitHub Desktop.
Save neerajkumar161/23e1008b9423b0191e283e249a17fc1a to your computer and use it in GitHub Desktop.
db/mongodb.ts
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