Skip to content

Instantly share code, notes, and snippets.

@Kasun002
Created June 29, 2023 02:08
Show Gist options
  • Save Kasun002/f7fc0ae0ffc085b4a5f2cb41bc0dfa46 to your computer and use it in GitHub Desktop.
Save Kasun002/f7fc0ae0ffc085b4a5f2cb41bc0dfa46 to your computer and use it in GitHub Desktop.
Express JS project Mongo-DB connection
import mongoose from 'mongoose';
const dbUri = "Your mongo DB URI" // This should be prick from .env file
export default async () => {
await mongoose.connect(dbUri,{})
.then(() => {
console.log('Mongodb Connection to database');
})
.catch(err => {
console.log(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment