Blog categories

Hello.I am trying to make category buttons for a blog application.

EJS:


<div class="container mt-2 mb-5">
    <p class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;  border:none;">Action</p>
    <p  class="btn btn-success   mr-2 categoryLink" style="background-color:#7f8c8d;  border:none;">Horror</p>
    <p  class="btn btn-success  mr-2 categoryLink" style="background-color:#7f8c8d;   border:none;">Romance</p>
     <p  class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;    border:none;">Sci-fi</p>
    <p class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;   border:none;">Drama</p>
  <p class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;   border:none;">Tech</p>
    <p class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;   border:none;">Life</p>
  <p  class="btn btn-success mr-2 categoryLink" style="background-color:#7f8c8d;   border:none;">Gossip</p>
    </div>

Axios post request:

  let categories = document.querySelectorAll('.categoryLink');

  Array.from(categories).forEach((category)=>{
    category.addEventListener('click',()=>{
      axios.post('/articles/displayCategoryArticle',category.innerText).then(function(res){ 

    });
  })
});

Category route :

  displayCategoryArticle:(req,res)=>{
  let categoryName = Object.keys(req.body)[0];
  categoryName = categoryName.charAt(0).toLowerCase() + categoryName.slice(1);

  Article.find({category:categoryName}).then((articles)=>{
  req.articles = articles;
  console.log(req.articles);
  res.render('testHP',{articles:articles});
  })
  }

The issue is that I can’t render the articles.I get back an array with the results after clicking a category button.

Github:

Have you succeeded in hooking up a single button to a single category? It might be easier to start simple and progressively add complexity.

I am not sure if this is what you asked for but when I click on a button I can get all the articles with that category name (E.g : Click on romance I can get all the articles with romance category and display them on the console) ,so I think I managed to hook them up .My mother tongue isn’t english btw … ;(

I am not sure why I can’t render the articles that I get back

Wish I know more about Axios. Would be easier to help debug if you had a live deployment!