Reputation: 686
I have a node.js server running on my local system which interacts with postgresql in the same system to fetch and save data. I want to access node.js server from my android app to save and fetch data from postresql. The problem is my app is not able to connect to localhost. As localhost for my phone is different from my local system and if I am providing my system's IP address then also its refusing the connection.
Upvotes: 3
Views: 3674
Reputation: 69
I was facing the same kind of issues
I wasn't able to call the API from emulator. I made it working by replacing localhost with 10.0.2.2:YOUR_PORT_NUMBER
I was able to call from an external device using ngrok (https://ngrok.com/)
If you want to call api without using external services go through this article may be helpful Link
Upvotes: 0
Reputation: 31
if you are using android emulator and trying to access the the host machine's
this should allow you to access the host machine's local host, but you will have to change this IP address to local IP address when running app on a device and connected to same network, to access from other network you need to open port(port forwarding I guess) in your router and talk ask your ISP to do the same.
here's a link to similar question : here
Upvotes: 1
Reputation: 686
I made server listen to hostname '0.0.0.0'. Initially I was not providing any hostname as argument in server.listen i.e it was like server.listen('portnumber') which I changed to server.listen('portnumber', '0.0.0.0');
Upvotes: 3