I'm a newbie to NodeJS and I'm using this API https://api.wazirx.com/api/v2/tickers to render it using EJS on my website. The server code I wrote is as follows
const express = require('express');
const request = require('request');
const app = express();
app.set('view engine', 'ejs');
const PORT = 3000 || process.env.PORT;
app.get("/", (req, res)=>{
let url = "https://api.wazirx.com/api/v2/tickers";
try{
request.get(url,{},(err, resp, body)=>{
if(err){
console.log(err);
}
else{
let jsonObject = JSON.parse(body);
console.log(jsonObject['wrxinr']['sell']);
res.render("home.ejs", {"data":jsonObject});
}
});
}
catch(err){
res.json({message:"Something went wrong."});
}
});
app.listen(PORT, ()=>{
console.log(`Listening on port ${PORT}`);
});
and my home.ejs file is as follows
<html>
<head>
<title>Wazirx Tickers API</title>
</head>
<body>
<% if(data != undefined) { %>
<% for(let i=0; i<data.length; i++) { %>
<p><%= data[i] %></p>
<% } %>
<% } else{ %>
<h4>sorry, cannot find what you wanted!</h4>
<% } %>
</body>
</html>
I can access wrxinr object using this data['wrxinr']['sell'] snippet. But, I want to render every Token on the webpage. How do I do this?
Any help would be appreciated. Thanks :)