Error: ENOENT: no such file or directory, stat ‘/opt/render/project/src/frontend/build/index.html’
got this error after trying to deploy it
wriiten the same code of server.js as you explained please explain.
my server.js code
const express = require(“express”);
const cors = require(“cors”);
const morgan = require(“morgan”);
const dotenv = require(“dotenv”);
const colors = require(“colors”);
const path = require(“path”);
const connectDb = require(“./config/connectDB”);
// config dot env file
dotenv.config();
//databse call
connectDb();
//rest object
const app = express();
//middlewares
app.use(morgan(“dev”));
app.use(express.json());
app.use(cors());
//routes
//user routes
app.use(“/api/v1/users”, require(“./routes/userroute”));
//transections routes
app.use(“/api/v1/transactions”, require(“./routes/transactionRoute”));
//static files
app.use(express.static(path.join(__dirname, “./frontend/build”)));
app.get(“*”, function (req, res) {
res.sendFile(path.join(__dirname, “./frontend/build/index.html”));
});
//port
const PORT = process.env.PORT||8090;
//listen server
app.listen(PORT, () => {
console.log(Server running on port ${PORT}
);
});
and my index.html is in folder frontend->build->index.html.
and also i ran npm run build command as well.