Everything works perfectly in localhost but after deploying it on cPanel I’m getting this error:
Operation xyz.findOne()
buffering timed out after 10000ms.
I have tried all possible solutions available on internet in last 3 days but no luck. 🙁
//index.js
const express = require("express");
require("dotenv").config();
const cors = require("cors");
const { fileURLToPath } = require("url");
const path = require("path");
const { connectDb } = require("./db/db.js");
const adminRouter = require("./routes/admin/admin.routes.js");
const candidateRouter = require("./routes/candidate/candidate.routes.js");
const employerRouter = require("./routes/employer/employer.routes.js");
connectDb(); //db connection
const app = express();
app.use(cors());
app.use(express.json());
// Serve static files from the build directory
app.use("/", express.static(path.join(__dirname, "build")));
// API routes
app.use("/api", adminRouter);
app.use("/api", candidateRouter);
app.use("/api", employerRouter);
// Serve the main HTML file for any other routes
app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
console.log("PORT:", process.env.PORT);
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
db.js
const mongoose = require("mongoose");
const url = process.env.MONGODB_URL;
module.exports.connectDb = async () => {
await mongoose
.connect(url)
.then(() => console.log("MongoDB connected"))
.catch((err) => console.log(err));
};
environment variable
MONGODB_URL=mongodb+srv://username:[email protected]/jobportal?retryWrites=true&w=majority&appName=Cluster0
I tried below:
- importing mongoose models in index.js
- whitelisted IP
- reset the Mongodb configuration
- changed code according to the available solutions.
- I’m already using aync and await.
New contributor
Piyush Rai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.