Bmi calculator using body parser in express (node.js)
const express = require("express");
const app=express();
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended:true}));
// Calculator
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);
})
// BMI
app.get("/bmiCalculator",function(req,res){
res.sendFile(__dirname+"/bmiCalculator.html");
});
app.post("/bmiCalculator",function(req,res){
var height=Number(req.body.height);
var weight=Number(req.body.weight);
var result=Math.floor(weight/(height*height));
res.send("Your BMI is:" + result);
});
app.listen(3000,function(){
console.log("Server started at port 3000");
})
Comments
Post a Comment