I am new to web development(creating my first local server) and I can’t understand what I am doing wrong.
Following is my code on HTML:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<form action= "/" method="post">
<input type="text" name="num1" placeholder="First Number">
<input type="text" name="num2" value="" placeholder="Second number">
<button type="submit" name="submit">Calculate</button>
</form>
</body>
</html>
and JS :
var express = require("express");
var app = express();
app.get("/", function(req, res)
{
res.sendFile(__dirname + "/index.html");
})
app.post("/index.html", function(req,res){
res.send("Thanks for posting that!");
});
app.listen(3000, () => {
console.log("Server is running on port 3000")
});
But the Output I am getting when I press (calculate button) is the (index of C:/) i.e the directory of C and all the files in it …
image of output i am getting after i press calculate
What I am using:
noje.js, html5 , nodemon , hyper terminal , atom text editor
What I want to achieve:
A server that sends a request to display an html form that accepts 2 numbers and then displays the sum as a text message when some1 presses the calculate(submit) button.
What I have tried:
- form action= “/index.html” method=”post”
Well, like u guessed, just refreshes the form
- app.post(“/”, function(req,res)
Same Output(index of C)
Sorry For asking noob questions .. but can you please explain to me what I am doing wrong and point me in the right direction.