Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

462
Vistas
POST Request failed with status code 500 at IncomingMessage.handleStreamEnd Express.js

I am creating a HTTP request for a CRUD application through JS. The objective of this request is to simply create a record in the Logins database of a new user account. When I try to request this, I get a 500 error:

I make the request in a silly little test script:

const axios = require("axios");

var http = axios.create({
    baseURL: "http://localhost:8080/",
    headers: {
        "Content-type": "application/json"
    }
});

class UserDataService {
    getAll(){
        return http.get("/users");
    }

    get(id){
        return http.get(`/users/${id}`);
    }

    create(data){
        return http.post("/users", data);
    }

    update(id, data){
        return http.put(`/users/${id}`, data);
    }

    delete(id){
        return http.delete(`/users/${id}`);
    }

    findByUsername(username){
        return http.get(`/users?username=${username}`);
    }

    authenticateLogin(data){
        console.log(data);
        return http.get("/login");
    }
}

function main(){
    const uds = new UserDataService();
    // http://localhost:8080'/api/users
    uds.create({
        username: "root",
        email: "root@enron.com",
        password: "password"
    }).catch(err => {
        console.log(err);
    });
}

main();

This gets routed into users.routes.js:

router.post("/users", users.create);

Which then gets sent to users.controller.js:

exports.create = (req, res) => {
    console.log("User being created");
    const user = {
        username: req.body.username,
        email: req.body.email,
        password: crypto.createHash("md5").update(req.body.password).digest("hex")
    };
    Users.create(user)
        .then(data => {
            res.send(data)
        })
        .catch(err => {
            res.status(500).send({
                message: err.message || "Error occurred when creating a user"
            })
        });
};

This is my error:

Error: Request failed with status code 500
    at createError (/home/amicharski/WebstormProjects/profrec/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/amicharski/WebstormProjects/profrec/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/home/amicharski/WebstormProjects/profrec/node_modules/axios/lib/adapters/http.js:293:11)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm not sure how this worked, but I put quotes around the username, email, and password field names when I called the API:

function main(){
    const uds = new UserDataService();
    // http://localhost:8080'/api/users
    uds.create({
        "username": "root",
        "email": "root@enron.com",
        "password": "password"
    }).catch(err => {
        console.log(err);
    });
}

main();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda