const express = require("express");
const bodyparser = require("body-parser");
const app = express();
// it can be bodyparser.text() so it will pass data as text or .json() or .urlencoded() which we use to get data from a form 
app.use(bodyparser.urlencoded({ extended: true }));
app.get("/", function (req, res) {
    res.sendFile(__dirname + "/index.html");
})
// npm install body-parser will allow us to collect data we get from post 
// req.body will act as an object 
// we use number because the data is parsed as text 
app.post("/", function (req, res) {
    var num1 = Number(req.body.num1);
    var num2 = Number(req.body.num2);
    if (req.body.operation == "1") {
        var result = num1 + num2;
        res.send("the result of the calculation is " + result);
    }
    else if (req.body.operation == "2") {
        var result = num1 - num2;
        res.send("the result of the calculation is " + result);
    }
    else if (req.body.operation == "3") {
        var result = num1 * num2;
        res.send("the result of the calculation is " + result);
    }
    else if (req.body.operation == "4") {
        var result = num1 / num2;
        res.send("the result of the calculation is " + result);
    }
})
app.listen(3000, function () {
    console.log("server is running at port 3000");
})