App won't connect to backend

Files such as package.json, package-lock.json, etc are missing.

If you are not comfortable with git, you can simply remove the “node_modules” folders from both your mobile and web folders, then zip them (mobile and server directories) and upload them to Dropbox or Google Drive.

When working with git, we add the node_modules folder to .gitignore since we can download these packages by running npm install.

PS: please zip them instead of rar, or put the whole folder on Dropbox.

Even I am getting the same problem.
Object {
“config”: Object {
“adapter”: [Function xhrAdapter],
“baseURL”: “192.168.137.1:9000/api”,
“data”: undefined,
“headers”: Object {
“Accept”: “application/json”,
},
“maxBodyLength”: -1,
“maxContentLength”: -1,
“method”: “get”,
“params”: Object {},
“timeout”: 0,
“transformRequest”: Array [
[Function transformRequest],
],
“transformResponse”: Array [
[Function transformResponse],
],
“transitional”: Object {
“clarifyTimeoutError”: false,
“forcedJSONParsing”: true,
“silentJSONParsing”: true,
},
“url”: “/listings”,
“validateStatus”: [Function validateStatus],
“xsrfCookieName”: “XSRF-TOKEN”,
“xsrfHeaderName”: “X-XSRF-TOKEN”,
},
“data”: null,
“duration”: 14,
“headers”: null,
“ok”: false,
“originalError”: [Error: Network Error],
“problem”: “NETWORK_ERROR”,
“status”: null,
}

I was able to call the backend through browsers.
Tried changing IPV4 IPV6 and gateway IP addresses

Can you upload the mobile and backend code to Dropbox (just make sure that node_modules folder is not uploaded as it will increase the file size)?

I have uploaded the project and its backend without node modules here. Please try to help me

I ran your code. You just need to update your baseURL line in the client.js to this:

const apiClient=create({baseURL:"http://192.168.137.1:9000/api"});

Thank you bro. It is working. The problem is with giving wrong ip address. Thats a lot

You are a savior my friend! thank you <3

Hey Sufian, can you please help me out with my code my backend is also not getting connected I am trying it since 3 days. I have attached below the link to my files. Please help me out

link: React Native.zip - Google Drive

1 Like

hey everyone so I was getting the Network Error before, and couldn’t figure out why it wasn’t working. I was able to use localhost and 127.0.0.1 (just learned they are the same thing) but as Mosh said, using localhost won’t work for android devices.

I then found a post in the React Native Developers discord channel where someone said that you can’t fetch from localhost because localhost is your own phone (if you try using localhost and running the app on your own physical iOS device, you’ll see that you still get the network error even though it works in the simulator). The same person who posted the above mentioned message then said that you need to use your computer’s LAN IP address. I had been using the IP address i found when I googled “what is my IP address” since I didn’t know there were different types/purposes.

After following the instructions on the following site (get your LAN IP address in MacOSX), and I have fixed the issue and can attest that using my LAN IP address allows my iOS simulator, iOS physical device, AND android simulator to successfully connect to my API.

As a reminder, you’ll have to use the LAN IP address in the baseURL in client.js in the client AND assetsBaseUrl in development.json in the API.

I hope this helps!

2 Likes

Please refer to lorenco’s comment. He’s right that you need to put in your machine’s public IP address in place of localhost or 127.0.0.1.

Hello, I have also tried searching for my IP address on google as I am a Windows user can you suggest to me a website where I can get exactly what I am looking for?

this might be helpful, i’m not sure how up-to-date it is though. let us know in case others are in the same boat as you! How to find your LAN IP address - YouTube

I really want to connect with you Sir,…can you just send me a message on my email
forexpave@gmail.com

At the client.js file, replace the ip with your Wireless LAN IP, that can be found using ipconfig on windows command terminal and ifconfig on linux.

Hello bebo7,
Can you please tell us if you could connect to the backend?
I have the same problem as you.

Well, I tried all of the possibilities, I used IPv6, './listings/, localhost.
I also downloaded the zipped files and tried them, every time I got “problem”: “NETWORK_ERROR”.
I don’t know Mosh why didn’t figured out a better solution for backend, as I see a lot of people has the same problem. Is there somebody who resolved the problem?

The response of the request:
Object {
“config”: Object {
“adapter”: [Function xhrAdapter],
“baseURL”: “http://192.168.0.10:9000/api”,
“data”: undefined,
“headers”: Object {
“Accept”: “application/json”,
},
“maxContentLength”: -1,
“method”: “get”,
“params”: Object {},
“timeout”: 0,
“transformRequest”: Array [
[Function transformRequest],
],
“transformResponse”: Array [
[Function transformResponse],
],
“url”: “/listings”,
“validateStatus”: [Function validateStatus],
“xsrfCookieName”: “XSRF-TOKEN”,
“xsrfHeaderName”: “X-XSRF-TOKEN”,
},
“data”: null,
“duration”: 69619,
“headers”: null,
“ok”: false,
“originalError”: [Error: Network Error],
“problem”: “NETWORK_ERROR”,
“status”: null,
}

Try using your public IP address as per this comment. IP addresses starting in the form 192.xx.xx.xx are not public addresses.

same problem here too…
read and implemented all the comments step by step… but no success… if someone has solved this problem please share here… will be gratefull…

Solved the same issue… took the following steps…

  1. Reinstalled backend.
  2. Used ipconfig to get IPv4 address.

hope this solves it for all…