Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

461
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!