I want to run my React Native app on my local Android Device. The app uses Node js APIs for fetching data from mysql. The problem is, my android device can't access node js app which results in no data. The app works fine on Android Emulator on using address 10.0.2.2 but can't access this on Android Device P.S The node js APIs are o local server (localhost:3000)
So I solved it like this. 1. I got my ip address from cmd using ipconfig 2. In node js, I wrote the server listening code like this
const hostname = "192.168.2.103";
const port = "3002";
app.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Now the app will run on this ip address instead of localhost and hence we can access it anywhere on the same network even in React Native fetching from APIs process
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With