const tableBody = document.querySelector('#tableBody'); var url = 'http://localhost:3000/api/products'; fetch(url) .then(res => res.json()) .then(res => { res.forEach(prod => { console.log(prod.name); let tr = document.createElement('tr'); let tdId = document.createElement('td'); let tdName = document.createElement('td'); let tdPrice = document.createElement('td'); tableBody.appendChild(tr); tr.appendChild(tdId); tr.appendChild(tdName); tr.appendChild(tdPrice); tdId.textContent = prod.id; tdName.textContent = prod.name; tdPrice.textContent = prod.price; }); });