Answer the question
In order to leave comments, you need to log in
How to return a response to the client if a connection to Mongo is not established?
Is there a way to send a message in JSON to the client (instead of outputting to the console) when a connection to Mongo is not established (for example, it is simply not running or has crashed)?
I tried several options, this is the last one:
mongoose.connect(process.env.DATABASE, { useMongoClient: true, autoReconnect: true, reconnectInterval: 1000 }, )
.then(() => {
console.log('Connected to Server successfully!')
})
.catch((err) => {
console.log('Unable to connect to the server. Please start the server. Error:', err.message)
return err
})
res.json
user?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question