I will provide you my codes
// controllers/articleController.js

const path = require("path");
const fs = require("fs-extra");

// Function to handle uploading a new article
const addArticle = async (req, res) => {
try {
const { title, content, author } = req.body;
const headingImage = req.file;


if (!title || !content || !author || !headingImage) {
  return res.status(400).json({ message: "All fields are required." });
}

// Create a unique article ID (preferably using a UUID for uniqueness)
const { v4: uuidv4 } = require("uuid");
const articleId = uuidv4();
const articlesDir = path.join(__dirname, "../assets/articles");
const articlePath = path.join(articlesDir, articleId);

await fs.ensureDir(articlePath);

// Save heading image
const imagePath = path.join(articlePath, headingImage.originalname);
await fs.move(headingImage.path, imagePath);

// Save content and author
await fs.writeFile(path.join(articlePath, "content.md"), content);
await fs.writeFile(path.join(articlePath, "author.txt"), author);

res
  .status(201)
  .json({ message: "Article uploaded successfully.", articleId });
} catch (error) {
console.error(error);
res.status(500).json({ message: "Server error while uploading article." });
}
};

// Function to fetch all user articles and external news, with user articles on top
const getArticles = async (req, res) => {
try {
const articlesDir = path.join(__dirname, "../assets/articles");
let userArticles = [];


if (await fs.pathExists(articlesDir)) {
  const articleFolders = await fs.readdir(articlesDir);

  userArticles = await Promise.all(
    articleFolders.map(async (folder) => {
      const articlePath = path.join(articlesDir, folder);
      const files = await fs.readdir(articlePath);

      const article = {
        id: folder,
        title: "",
        headingImage: "",
        content: "",
        author: "",
        isUserArticle: true, // Flag to identify user articles
      };

      for (const file of files) {
        if (file.toLowerCase().startsWith("headingimage")) {
          article.headingImage = `/assets/articles/${folder}/${file}`;
        } else if (file === "content.md") {
          article.content = await fs.readFile(
            path.join(articlePath, file),
            "utf-8"
          );
        } else if (file === "author.txt") {
          article.author = await fs.readFile(
            path.join(articlePath, file),
            "utf-8"
          );
        }
      }

      return article;
    })
  );
}

// Placeholder for fetching external news articles
// Assuming you have a service or another controller to fetch news
// For demonstration, we'll leave this empty
const externalNews = []; // Replace with actual data fetching if required

// Combine user articles and external news, with user articles first
const combinedArticles = [...userArticles, ...externalNews];

res.json(combinedArticles);
} catch (error) {
console.error(error);
res.status(500).json({ message: "Server error while fetching articles." });
}
};

// Function to fetch a single article by ID (only for user articles)
const getArticleById = async (req, res) => {
try {
const { id } = req.params;
const articlePath = path.join(__dirname, "../assets/articles", id);


if (!(await fs.pathExists(articlePath))) {
  return res.status(404).json({ message: "Article not found." });
}

const files = await fs.readdir(articlePath);

const article = {
  id,
  title: "",
  headingImage: "",
  content: "",
  author: "",
  isUserArticle: true,
};

for (const file of files) {
  if (file.toLowerCase().startsWith("headingimage")) {
    article.headingImage = `/assets/articles/${id}/${file}`;
  } else if (file === "content.md") {
    article.content = await fs.readFile(
      path.join(articlePath, file),
      "utf-8"
    );
  } else if (file === "author.txt") {
    article.author = await fs.readFile(
      path.join(articlePath, file),
      "utf-8"
    );
  }
}

res.json(article);
} catch (error) {
console.error(error);
res
.status(500)
.json({ message: "Server error while fetching the article." });
}
};

// ... existing handleControllerError if needed

module.exports = {
getArticles,
addArticle,
getArticleById,
};

// controllers/newsController.js

const { getCachedData } = require("../utils/cacheHelper");
const axiosInstance = require("../utils/axiosInstance");

// Centralized Error Handling for Controller
const handleControllerError = (error, res, functionName) => {
if (error.response) {
// API responded with a status code outside 2xx
console.error(
Error in ${functionName}: ${error.response.status} - ${JSON.stringify( error.response.data )}
);
res.status(error.response.status).json({
message: error.response.data.message || Error in ${functionName},
details: error.response.data,
});
} else if (error.request) {
// No response received from API
console.error(No response received in ${functionName}:, error.request);
res.status(503).json({
message: No response from Football API during ${functionName},
});
} else {
// Other errors
console.error(Error in ${functionName}:, error.message);
res
.status(500)
.json({ message: Internal server error in ${functionName} });
}
};

// Function to fetch top 10 players for a specific club
const getTopPlayersByClub = async (req, res) => {
const { club } = req.params; // e.g., 'barcelona', 'realmadrid'
const cacheKey = top_players_${club.toLowerCase()};
const fetchFn = async () => {
try {
const response = await axiosInstance.get(
/players/${encodeURIComponent(club.toLowerCase())}
);
// Assuming the API returns an array of player objects
const topPlayers = response.data.slice(0, 10); // Get top 10 players
return topPlayers;
} catch (error) {
throw error;
}
};

try {
const topPlayers = await getCachedData(cacheKey, fetchFn);
res.status(200).json({
club: club.charAt(0).toUpperCase() + club.slice(1),
topPlayers,
});
} catch (error) {
handleControllerError(error, res, getTopPlayersByClub ${club});
}
};

// Existing functions (getAllPlayers, getPlayersTransfers, etc.)

const getAllPlayers = async (req, res) => {
const cacheKey = "all_players";
const fetchFn = async () => {
const response = await axiosInstance.get("/players");
return response.data; // Assuming it's an array of players
};

try {
const players = await getCachedData(cacheKey, fetchFn);
res.status(200).json(players);
} catch (error) {
handleControllerError(error, res, "getAllPlayers");
}
};

const getPlayersTransfers = async (req, res) => {
const cacheKey = "players_transfers";
const fetchFn = async () => {
const response = await axiosInstance.get("/players/transfers");
return response.data; // Assuming it's an array of transfers
};

try {
const transfers = await getCachedData(cacheKey, fetchFn);
res.status(200).json(transfers);
} catch (error) {
handleControllerError(error, res, "getPlayersTransfers");
}
};

const getPlayersNews = async (req, res) => {
const cacheKey = "players_news";
const fetchFn = async () => {
const response = await axiosInstance.get("/players/news");
return response.data; // Assuming it's an array of news articles
};

try {
const news = await getCachedData(cacheKey, fetchFn);
res.status(200).json(news);
} catch (error) {
handleControllerError(error, res, "getPlayersNews");
}
};

const getBettingLaLiga = async (req, res) => {
const cacheKey = "betting_laliga";
const fetchFn = async () => {
const response = await axiosInstance.get("/betting/laliga");
return response.data; // Assuming it's betting information
};

try {
const laLigaData = await getCachedData(cacheKey, fetchFn);
res.status(200).json(laLigaData);
} catch (error) {
handleControllerError(error, res, "getBettingLaLiga");
}
};

const getBettingPremierLeague = async (req, res) => {
const cacheKey = "betting_premierleague";
const fetchFn = async () => {
const response = await axiosInstance.get("/betting/premuire-league"); // Fixed endpoint spelling
return response.data; // Assuming it's betting information
};

try {
const premierLeagueData = await getCachedData(cacheKey, fetchFn);
res.status(200).json(premierLeagueData);
} catch (error) {
handleControllerError(error, res, "getBettingPremierLeague");
}
};

// ... other functions as needed

module.exports = {
getAllPlayers,
getPlayersTransfers,
getPlayersNews,
getTopPlayersByClub,
getBettingLaLiga,
getBettingPremierLeague,
// ... other exports
};

// models/Article.js

const mongoose = require("mongoose");

const ArticleSchema = new mongoose.Schema({
title: { type: String, required: true },
content: { type: String, required: true },
author: { type: String, required: true },
headingImageUrl: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
});

module.exports = mongoose.model("Article", ArticleSchema);

// routes/articleRoutes.js

const express = require("express");
const {
getArticles,
addArticle,
getArticleById,
} = require("../controllers/articleController");
const router = express.Router();
const fs = require("fs");
const authenticateToken = require("../middlewares/authMiddleware");
const multer = require("multer");
const path = require("path");

// Configure Multer for file uploads
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "uploads/"); // Temporary upload directory
},
filename: (req, file, cb) => {
const uniqueSuffix = ${Date.now()}-${Math.round(Math.random() * 1e9)};
cb(null, ${uniqueSuffix}-${file.originalname});
},
});

const upload = multer({
storage,
limits: { fileSize: 5 * 1024 * 1024 }, // Limit file size to 5MB
fileFilter: (req, file, cb) => {
const filetypes = /jpeg|jpg|png|gif/;
const mimetype = filetypes.test(file.mimetype);
const extname = filetypes.test(
path.extname(file.originalname).toLowerCase()
);


if (mimetype && extname) {
  return cb(null, true);
}
cb(new Error("Only image files are allowed!"));
},
});

// Routes for user articles
router.get("/", getArticles); // GET /api/articles
router.post(
"/add",
authenticateToken,
upload.single("headingImage"),
addArticle
); // POST /api/articles/add
router.get("/:id", getArticleById); // GET /api/articles/:id

module.exports = router;

// routes/newsRoutes.js

const express = require("express");
const {
getAllPlayers,
getPlayersTransfers,
getPlayersNews,
getBettingLaLiga,
getBettingPremierLeague,
// ...other controller imports
} = require("../controllers/newsController");
const router = express.Router();

// New Routes
router.get("/players", getAllPlayers); // GET /players
router.get("/players/transfers", getPlayersTransfers); // GET /players/transfers
router.get("/players/news", getPlayersNews); // GET /players/news

router.get("/betting/laliga", getBettingLaLiga); // GET /betting/laliga
router.get("/betting/premuire-league", getBettingPremierLeague); // GET /betting/premuire-league

// ...other routes

module.exports = router;

require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const newsRoutes = require("./routes/newsRoutes");
const scoreRoutes = require("./routes/scoreRoutes");
const taskQueue = require("./taskQueue/matchUpdateQueue");
const standingsRoutes = require("./routes/standingsRoutes");
const fixturesRouter = require("./routes/fixturesRouter");
const leagueRoutes = require("./routes/leagueRoutes"); // New
const leaguesRoutes = require("./routes/leaguesRoutes"); // New
const articleRoutes = require("./routes/articleRoutes");
const cors = require("cors");
const path = require("path");
const app = express();

// CORS configuration
app.use(
cors({
origin: "http://localhost:3000", // Replace with your frontend URL
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
})
);

const PORT = process.env.PORT || 5000;

// Connect to MongoDB
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to MongoDB"))
.catch((err) => console.error("MongoDB connection error:", err));

// Middleware
app.use(express.json());

// Routes
app.use("/assets", express.static(path.join(__dirname, "assets")));
app.use("/uploads", express.static(path.join(__dirname, "uploads")));
app.use("/api/news", newsRoutes);
app.use("/api/scores", scoreRoutes);
app.use("/api/articles", articleRoutes);
app.use("/api", standingsRoutes);
app.use("/api", fixturesRouter);
app.use("/api/leagues", leaguesRoutes);
app.use("/api/league", leagueRoutes);

// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something broke!");
});

// Test route
app.get("/api/test", (req, res) => {
res.json({ message: "Test route working" });
});

// Start server
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
});

// Start task queue worker (for fetching live scores)
taskQueue.start();

module.exports = app; // Export for testing purposes

football-app-backend/controllers and football-app-backend/assets/articles/content.md and author.txt and football-app-backend/uploads/headingImage.jpg
this is my file structure
[Error: ENOTDIR: not a directory, scandir 'C:\Node js programs\Football App\football-app-backend\assets\articles\author.txt'] {
errno: -4052,
code: 'ENOTDIR',
syscall: 'scandir',
path: 'C:\Node js programs\Football App\football-app-backend\assets\articles\author.txt'
}
This is the error I'm getting
resolve it