K
K
kirillgenets2019-12-05 22:49:42
API
kirillgenets, 2019-12-05 22:49:42

How to forward data from API through Node.js to React app?

Hello! I'm building my own cryptocurrency tracker in React for practice. I need to use the CoinMarketCap API to get data about cryptocurrencies in order to use them in my application. The thing is, I can't get this data with a simple request to the right address, even using the CMC_PRO_API_KEY key from the client js, because Quote from API documentation:

Making HTTP requests on the client side with Javascript is currently prohibited through CORS configuration. This is to protect your API Key which should not be visible to users of your application so your API Key is not stolen. Secure your API Key by routing calls through your own backend service.

So. I do not own Node.js, but I can make a request to the server and get a response. The only question is - how to transfer all this to your React application? Maybe I should create a JSON file through a node? Just in this case, I need new data to be received every time the application is launched, how do I run Node.js code when the page is launched?
How would you advise to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Lambov, 2019-12-06
@maxilamb


  1. use express.js
    app.get('/api/v1/bitcoin', function (req, res) {
    //запрос coinmarketcap 
    .then(response => res.json(response))
    .catch(() => res.send("Ops something went wrong"))
    })

    in package.json write a proxy to the local node.js server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question