//mongoose connection function
const connectDB = (url) => {
return mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('Connected to database'))
.catch(err=>console.log(`DB CONNECTION ERR ${err}`))
}
const port = process.env.PORT || 5000
const mongoURI = process.env.MONGO_URI
//start
const start = async () => {
try {
await connectDB(mongoURI)
app.listen(port, () => console.log(`Server running at ${port}`))
} catch (error) {
console.log(error);
}
}
start()
This is my basic server setup. I tried messing with mongoose connection setup and app.listen() too but the catch block (in try-catch) didn't handle anything. Does the catch block only handle the errors we throw?