1

I have json file and created node.js server to set endpoint and then get this data via my React Native application. If I'm not wrong it worked correctly in friday but I had to mess something up and now I totally don't know how to fix it. All time I get error:

Possible Unhandled Promise Rejection (id: 0): TypeError: Network request failed self.fetch/http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:27859:18 dispatchEvent@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:29144:13 setReadyState@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:28897:15 __didCompleteResponse@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:28724:11 send/<@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:28834:18 emit@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:4538:15 __callFunction@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:2608:22 callFunctionReturnFlushedQueue/<@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:2385:11 __guard@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:2561:13 callFunctionReturnFlushedQueue@blob:http://192.168.1.39:8081/1c49a23b-7fbb-c640-a946-c1e001192c92:2384:9 onmessage@http://192.168.1.39:8081/debugger-ui/debuggerWorker.js:72:25

my Node server:

const filename = './logos.json';

const server = http.createServer((req, res) => {

        if (req.url === "/logo") {
            res.writeHead(200, { "Content-Type": "application/json" });
            fs.createReadStream(__dirname + "/logos.json").pipe(res)
        }
})
server.listen(3000, (err) => {
    if (err) throw err;
    console.log('server is listening on port 3000');
})

and my RN code :

syncLogoData = () => {
    fetch('http://localhost:3000/logo')
        .then(resp => resp.json())
        .then(data => console.log(data))
        .catch(err => console.log(err))
    }
2
  • 1
    your request is to port 3000 but error log shows 8081 http://192.168.1.39:8081 double check again Commented Apr 15, 2019 at 10:02
  • @naga-elixir-jar 8081 is where React Native packager runs. Commented Apr 15, 2019 at 10:07

1 Answer 1

1

Looks like you're trying to run this on a device. The device doesn't know localhost points to your server. In your syncLogoData, change the uri to http://ip_address:3000/logo and it should work.

Also helpful to open http://localhost:3000/logo on your computer browser to make sure your server code is correct.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks dude, I already solved this issue but in exactly same way as you just said So I'm gonna mark it as a correct answer:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.