0
votes

how do call an api running on localhost from react native.I am using expo cli and running the app on real device using expo app.I tried fetch("https://localhost:3000") but that doesn't work pls help!!

Network Error at node_modules\axios\lib\core\createError.js:16:14 in createError at node_modules\axios\lib\adapters\xhr.js:84:24 in handleError at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyState at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse at node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue

1

1 Answers

0
votes

try to change https to http make sure your server is running on port 3000.

fetch("http://localhost:3000").then((data)=>{
  console.log(data);
});