Chetan Chetan - 1 year ago 1209
Node.js Question

React Native: fetch request failed with error - TypeError: Network request failed(…)

I am developing a simple app using React Native. I am testing it on Android device. I have created a Node.js server to listen to the requests, it is running at http://localhost:3333/.
Next, I am making a fetch request from Below is the code.

'method': 'GET',
'headers': {
'Accept': 'text/plain',
.then((response) => response.text())
.then((responseText) => {
.catch((error) => {

The code for the request handler at node server is below

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
app.get('/', function(req, res){
console.log('Request received for /');
res.send("this is the response from the server");

But, the fetch request is not working. The error I get in the Chrome console is:
TypeError: Network request failed(…).

How to make this work?

Answer Source

Since your Android device has an IP of its own, you need to point the URL to your computers IP address instead of just localhost. For example fetch('').

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download