Error shows when trying send request as form data

This is a simple calculator that can add numbers.
The html form loads correct to the browser but then once I submit the form, I get a 404 error code

Error code : Cannot POST /index.html


<!DOCTYPE html>
<html lang="en" dir="ltr">
    <meta charset="utf-8">
    <form action="index.html" method="post">
      <input type="text" name="num1" placeholder="First Number">
      <input type="text" name="num2" placeholder="Second Number">
      <button type="submit" name="submit">Calculate</button>

calculator.js :

//jshint esversion:6

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

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

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


  var num1 = Number(req.body.num1);
  var num2 = Number(req.body.num2);
  var result = num1 + num2;

  res.send("The result is: "+result);

//listen to port 3000
app.listen(3000, function(){
  console.log("Server listening on port 3000");

Leave a Comment