[SOLVED] Axios ERR_CONNECTION_RESET

Issue

This Content is from Stack Overflow. Question asked by KarolJ12

i have problem with node.js/Axios
When i trying to make call i’ve got error

xhr.js:220 GET http://localhost:5000/test net::ERR_CONNECTION_RESET

AxiosError {message: ‘Network Error’, name: ‘AxiosError’, code: ‘ERR_NETWORK’, config: {…}, request: XMLHttpRequest, …}

My node.js server

const express = require("express");
const app = express();
const cors = require("cors");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const Reservations = require("./models/reservations");
require("dotenv").config();

app.use(cors());
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));

const port = 5000;
app.listen(port);

app.get('/test', (req, res) => {
  console.log('test')

  res.send('test ')
})

My React components

Axios.get("http://localhost:5000/test").then(() => {
      console.log("test");
    }).catch((err) => {
      console.log(err)
    })

Can anyone help?

Solution

Try sending a response from your route:

fs.writeFile(urlPath, textData, 'utf8', (err) => {
    if (err) {
        console.log('write file => ' + err);
    } else {
        console.log('Finished writing');
        res.json({ msg: 'success' }); // send the client something
    }
});

Answered by djs


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?