I have this function on my backend:
app.get('/dashboard', async(req, res) => {
const customers = await stripe.customers.list();
customers.data.forEach(customer => {
console.log(customer.metadata);
});
res.render('dashboard.ejs', {customer: customers})
})
and on my front end:
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>NAME</th>
<th>EMAIL</th>
<th>ACTIONS</th>
</tr>
</thead>
<tbody>
<% if(customer.length){
for(var i = 0;i < customer.length;i++) { %>
<tr>
<td><%=customer[i].NAME%></td>
<td><%=customer[i].EMAIL%></td>
<% }
}else{ %>
<% } %>
</tbody>
</table>
however, i am trying to pass the METADATA to the front end. and within the metadata object, i have name and email. So on the front end, i tried:
<%=customer[i].METADATA.NAME%>
but it returned nothing. and same on the backend. how can i fix this?
In the comments above, by fetch I mean the term fetch you need to some how connect to your backend to accept the data on front end. You can use ajax, axios, fetch API etc.... Below I used ajax to show how to get data from back end. Feel free to comment if you have any questions?
var data_from_backend;
$.ajax({
type: 'GET',
data: 'data_to_send_to_backend',
url: 'server_URL',
success: function(getMetadata) {
$.each(JSON.parse(getMetadata), function(myMetadata) {
data_from_backend = myMetadata.the_name_of_data_set_on_backend
})
},
error: function(data) {
console.log('Something went wrong.');
}
});
console.log(data_from_backend)