Netlify function javascript fetch not working

I am trying to call API in Netlify function and pass data to the client. I tried fetch and axios but still have problems with getting the function to work.

To make my problem more simple I switched to API with no key and made sure that it works when called on client side.

I would be super grateful if someone help me

Hey @PabloBerry44 — have you installed node-fetch and does it appear in your package.json file?

The error on the screenshot is reporting that you don’t have node-fetch installed.

1 Like

Thank you @whitep4nth3r for your answer. I didn’t install node-fetch at this point and did it later. I ran into other errors and tried axios one more time and it actually worked for me.

Here is a screenshot of working Netlify function that calls API.

Please let me now if this way of calling API is not deprecated and up to todays standards.

Thank You :slight_smile:

Yep, using axios is perfectly valid!

I can take a guess at the errors you came across when using node-fetch. For anyone else that finds this blog post via a Google search or whatever, this blog post will help diagnose some issues!

1 Like