首页 > 解决方案 > Network request error setTimeout$argument_0

问题描述

I'm using React Native and Node js to build an app.

When I try to send 'POST' request, I get an ERROR to the Command:

setTimeout$argument_0.

The full Error:

Network request failed

The code:

    fetch('myIP:3000/signup',
        {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                'email':values.email,
                'password': values.password
            })
        })
        .then(res=>{res.json()})
        .then(data=>console.log('reach! ' + data))
        .catch((err)=> console.log(err))

Edit: adding the fetch code

const { mongoURI } = require('./keys');
const express = require('express');
const mongoose = require('mongoose');
const User = require("./models/User");
const app = express();
const PORT = 3000;
app.use(express.json());

// database connection
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
  .then((result) => {app.listen(PORT); console.log('connected server ' + PORT)})
  .catch((err) => console.log(err));

app.post('/signup', async (req, res) => {
  
  const { email, password } = req.body;

  try {
    const user = await User.create({ email, password });
    const token = createToken(user._id);
    res.cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 });
    res.status(201).json({ user: user._id });
   
  }
  catch(err) {
    const errors = handleErrors(err);
    res.status(400).json({ errors });
  }
})

Anyone who knows how to solve that error?

标签: javascriptnode.jsreact-nativefetch

解决方案


推荐阅读