I’m building a web development project and my server is running properly and my application is getting connected to MongoDB as well but when i open the local server in this case i’m using localhost:5001 then instead of getting the desired output i’m getting the text “Cannot Get /” and when i tried inspecting as well there is nothing, I restarted the server several time and refreshed my MongoDB and restarted my Postman application as well before it was running properly but after i did some code for nav bar it is happening since and i tried everything but no luck
import express from "express";
import dotenv from "dotenv";
import { connectDB } from "./config/db.js";
// import req from "express/lib/request.js";
// import res from "express/lib/response.js";
import productRoutes from "./routes/product.route.js"
import cors from "cors";
dotenv.config();
const app = express();
const PORT = process.env.PORT || 5001
app.use(cors());
app.use(express.json()); // allows us to accept json data in the req.body
app.get('/', (req, res) => {
console.log('Root route accessed'); // This will log to the console
res.send('API is running...');
});
app.use((req, res, next) => {
console.log(`Request Method: ${req.method}, Request URL: ${req.url}`);
next();
});
app.use("/api/products", productRoutes);
app.listen(PORT, () => {
connectDB();
console.log('Server Started at http://localhost:'+ PORT);
});
This is my server.js file