To detect the IP address our server is running on, I use the following code:
const localhostIP = Constants.linkingUri.split(':')[1].replace('//', '');
This works for testing via Wifi connections. It returns the Wifi address of my laptop.
However, when debugging on USB, I use:
npx expo start --localhost --android
Now this line of code returns 127.0.0.1
as address and I cannot use it as server address. The server runs on my laptop and needs to be called from its LAN IP address.
How do I retrieve the LAN IP address of my laptop from JavaScript using Expo and React Native?
I tried using the following packages:
react-native-network-info
-> returns null
expo-network
-> returns 0.0.0.0
Any help would be greatly appreciated
Fixed the issue by grabbing the IP Address from the console and adding it to an environmental variable