0

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 :)

1 Answer 1

1

Loop over the object and display every propertie on it, i think there is a way, maybe at first try to loop over every propertie of an object

Sign up to request clarification or add additional context in comments.

1 Comment

umm thanks, but how do I do it. I'm new to JSON, I didn't quite understand what you said. Could you please provide some pseudo code or something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.