Backend API Test: Resolving Undefined Environment Property

While testing my Node.js backend with Postman, I encountered an error reading an undefined ‘env’ property. Below is my revised controller code with similar functionality:

// Add new article
export const addArticle = async (req, res) => {
  try {
    const { header, bodyContent } = req.body;
    const creator = await Member.findById(req.user.identifier);
    if (!header || !bodyContent) {
      throw new Error('Missing header or content');
    }
    if (!creator) {
      throw new Error('Creator not found');
    }
    const articleRecord = new Article({
      header,
      bodyContent,
      image: req.file ? req.file.originalname : null,
      creator: creator._id
    });
    await articleRecord.save();
    res.status(201).json(articleRecord);
  } catch (error) {
    res.status(500).json(error.message);
  }
};

// Fetch all articles
export const fetchArticles = async (req, res) => {
  try {
    const articles = await Article.find()
      .populate('creator', 'username')
      .sort({ header: 1 });
    res.status(200).json(articles);
  } catch (error) {
    res.status(500).json('Server error');
  }
};

// Retrieve a single article
export const fetchArticle = async (req, res) => {
  try {
    const article = await Article.findById(req.params.id)
      .populate('creator', 'username');
    if (!article) throw new Error('Article not found');
    res.status(200).json(article);
  } catch (error) {
    res.status(404).json(error.message);
  }
};

// Modify an article
export const modifyArticle = async (req, res) => {
  try {
    const { header, bodyContent } = req.body;
    const article = await Article.findById(req.params.id);
    if (!article) throw new Error('Article missing');
    article.header = header || article.header;
    article.bodyContent = bodyContent || article.bodyContent;
    if (req.file) article.image = req.file.originalname;
    await article.save();
    res.status(200).json(article);
  } catch (error) {
    res.status(400).json(error.message);
  }
};

hey iris, i luv ur approach! maybe the undefined prop is due to a misconfigured process.env. did u check if all env vars load corretly? curious how u handle config in other parts. any insights on preventing similar issues?