app.post("/yourPageUrl", (req, res) => {
var your codes goes here
//there is something have to remember is that req is you get the data from the form. (i.e in CI4 $this->request->getPost('name') you request it), and res is when client visit the url, then you response with something else. req comes first and then res. Do not fuck it up.
})
const express = require('express')
const bodyParser = require("body-parser");
const app = express();
const port = 3000
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get("/calculator", (req, res) => {
res.sendFile(__dirname + "/calculator.html");
})
app.post("/",(req, res) => {
var number1 = Number(req.body.num1);
var number2 =Number(req.body.num2);
var result = number1 + number2;
res.send("The result of the calculation is " + result);
})
app.get("/bmialculator", (req, res) => {
res.sendFile(__dirname + "/bmiCalculator.html");
})
app.post("/calculated", (req, res) => {
var weight = req.body.weight;
var height = req.body.height;
var bmi = weight / (height * height);
res.send("Your bmi is " + bmi);
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})