Axios (in React-native) not calling server in localhost Axios (in React-native) not calling server in localhost node.js node.js

Axios (in React-native) not calling server in localhost


The solution came from a different source, but I post it here to help others looking for the same issue. Basically I used Android AVD (emulator) to build the application. But the emulator is in fact another machine, and that's why it couldn't call the localhost.

To solve the probleme, I had to send the request in the following way:

https://10.0.2.2:3000/v1/test

instead of:

https://localhost:3000/v1/test


if u are using mac this solution worked for me.I am using React Native with Android Simulator ADV. Nexus Api 27

            axios.get('http://192.168.1.21:8686/api/v1/test')            .then(response => console.log(response))            .catch(err => console.log(err));

where the ip 192.168.1.21 is from system preferences > Network > Advanced > TCP/IP > IPv4 Address

I also tested axios.get('http://10.0.2.2:8686/bec/api/v1/test') where 10.0.2.2 is localhost from virtual machine to the computer but not worked.


Your Emulator is a device on it's own that is not running on the same IP(localhost or 127.0.0.1) as your web browser, postman or your server.

In order to make request to your server from your emulator you need to access your server via your computer IP Address:On windows get your IP Address by running ipconfig on the command prompt

On Unix terminal (Linux, Mac OS) run ifconfig to get your IP Address

Instead of http://localhost:port you should use http://your_ip_address:port

I didn't test it on Linux, Mac OS but its working perfectly on windows!