Skip to content

Instantly share code, notes, and snippets.

@popeating
Created November 3, 2023 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popeating/8f8a1275eff496b085a707b3ca44a120 to your computer and use it in GitHub Desktop.
Save popeating/8f8a1275eff496b085a707b3ca44a120 to your computer and use it in GitHub Desktop.
import mongoose from 'mongoose';
const MongoConnect = () => {
if (mongoose.connections[0].readyState) {
console.log('already connected');
return;
}
mongoose
.connect(process.env.MONGO_DB_URI)
.then(console.log('connected'))
.catch((e) => console.log('error', e));
};
export default MongoConnect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment