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

108
Views
Not getting response calculation from express server?

just tell me what is missing in my code?

here is my html code:-

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Calculator</title>
    <!-- <link rel="stylesheet" href="styles.css"> -->
    <style media="screen">
      body {background-color: powderblue;}
    </style>
  </head>
  <body>
    <h1>Calculator</h1>
    <form action="/" method="post">
      <input type="text" name="n1" placeholder="First Number">
      <input type="text" name="n2" placeholder="Second Number">
      <button type="button" name="button">Calculate</button>

    </form>
  </body>
</html>

Here is my Express js code:-

// jshint esversion:6

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

const 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.n1);
  var num2 = Number(req.body.n2);
  var result = num1 + num2;
  res.send("The result is: " + result)
});
app.listen(3000, function(){
  console.log("App is running on port 3000");
});

I have imported body-parser. But still not working. I want to get output as the Result on screen.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Use either

<button>Calculate</button>

(without the type attribute), or use

<input type="submit" value="Calculate"/>

Your <button type="button"> does not trigger a submission of the form.

about 4 years ago · Santiago Gelvez Report

0

<button type="button" name="button">Calculate</button>

to

<button type="submit" name="button">Calculate</button>

work for me

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