Attempting to send a post request to my webserver using axios, I have a client that collects user input to populate an array of strings. This data is then sent via a post request using axios for processing by the server:
if (parsedInput > 0 && parsedInput <= 8) {
let listOfNames = [];
for (let i=0; i<parsedInput; i++) {
let name = await rl.question(`Enter name #${i}\n`);
listOfNames.push(name);
console.log(`Added ${name} to list of players\n`);
}
axios.post('http://localhost:3000/start', {
names: listOfNames,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
Although my server is not yet configured to process the request, it should at least acknowledge receiving the request from the client:
const express = require('express');
const app = express()
const port = 3000
var listOfNames = [];
app.post('/start', async (req, res) => {
listOfNames = req.body.names;
console.log(listOfNames);
res.status(200).send("Names added");
});
app.get('/', function(req, res, next) {
res.send("Welcome to the homepage of bowling");
})
app.listen(port, () => {
console.log('Listening to request on port 3000');
});
However, upon sending the array of names, I encounter an ECONNRESET error:
AxiosError: read ECONNRESET
at AxiosError.from (...details about the error...)
The server never prints out the list of names, indicating that it might not be receiving the post request at all. How can I resolve this ECONNRESET error?