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

228
Views
Why I'm getting ERR_HTTP_INVALID_STATUS_CODE?

I am making a simple calculator that does calculation on server as a beginner project. This is the code I have written in .js file:

const express = require("express");
const bodyParser=require("body-parser");

var app = express();
app.use(bodyParser.urlencoded({extended: true}));

app.get("/", function (req, res) {
    res.sendFile(__dirname + "/index.html");
});

app.post("/",function(req,res){
    var num1=Number(req.body.num1);
    var num2=Number(req.body.num2);
    var num3=num1+num2;
    res.send(num3);  // gives error if i don't write it as string >>like
                     //res.send("your answer is"+num3); >> this one doesn't throw an error
})
app.listen(3001, function () {
    console.log("server started at port 3001");
});

Why is this so? I am a beginner so please explain simply.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This problem is happening because you are giving send a parameter which is a Number, that isn't supported by the method. Here is what the doc says:

res.send([body])

The body parameter can be a Buffer object, a String, an Object, Boolean, or an Array.

about 4 years ago · Santiago Trujillo 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!