Reputation: 458
I have an express app that uses MongoDB, and I'm trying to deploy it to Heroku.
After deployment, it seems to work, but after a few minutes, it crashes. Before it crashes if I try to make a request to the API I get the following error.
"message": "Operation `users.findOne()` buffering timed out after 10000ms",
When it does crash, these are the message that i get from heroku cli
These are the main files
server.js
import express from 'express'
import connectDb from './config/db.js'
import router from './routes/userRoutes.js'
import { errorHandler } from './middleware/errorMiddleware.js'
import cors from 'cors'
const port = process.env.PORT || 5000
connectDb()
const app = express()
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({extended: false}))
app.use('/api/user', router)
app.use(errorHandler)
app.listen(port, () => console.log(`server started on ${port}`))
db.js
import mongoose from "mongoose";
const connectDb = async () => {
try{
const conn = await mongoose.connect(process.env.URL)
console.log(`MonngoDb Connected: ${conn.connection.host}`)
} catch(error){
console.log(error)
process.exit(1)
}
}
export default connectDb
Procfile
web: node backend/server.js
The App works fine on my local machine but just crashes when deployed.
How can I fix this
Upvotes: 0
Views: 422