BMI Calculator using Express.js Last Updated : 13 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The Body Mass Index(BMI) is represented in terms of weight and height of an individual. It is the ratio of the weight of the body to the square of the height of the body in kilograms and meters respectively. BMI = (weight of body) / (height of body)2 Unit of weight: Kilogram(Kg); Unit of height: Meter(m); Unit of BMI is kg/m2 Approach: First, we write HTML code for creating a form in which we will take name, height(m), weight(kg) as input from the user.Import require modules and store it into app variablesends html and post the data on the specific route using this  app.post("/bmicalculator", function (req, res) { heigh = parseFloat(req.body.Height); weigh = parseFloat(req.body.Weight); bmi = weigh / (heigh * heigh);Check Condition for BMI using formula. Step-1: HTML <!DOCTYPE html> <html lang="en"> <head> <!-- title is used to provide a specific name to our web-page! --> <title>BMI-CALCULATOR</title> <!-- link function is used here, so that we can connect our css file with our html file externally --> <link rel="stylesheet" href="1.css" /> </head> <body> <div id="MAIN"> <h1 id="heading">BMI-CALCULATOR</h1> </div> <form action="/bmicalculator" method="post"> <input type="text" name="Name" placeholder="Enter your name!" /> <br /> <input id="Height" name="Height" placeholder="Enter your height(m)" /> <br /> <input id="Weight" name="Weight" placeholder="Enter your weight(kg)" /> <br /> <button class="btn" type="submit">Get-BMI</button> </form> </body> </html> Output: SIMPLE FORM Let's now write code for our calculations and functionalities which is the main part of our BMI-CALCULATOR. Step-2 Dependencies: express: npm install express bodyparser: npm install body-parser JavaScript //importing modules const express = require("express"); const bodyparser = require("body-parser"); // stores the express module into the app variable! const app = express(); app.use(bodyparser.urlencoded({ extended: true })); //sends index.html app.get("/bmicalculator", function (req, res) { res.sendFile(__dirname + "/" + "index.html"); }); //this is used to post the data on the specific route app.post("/bmicalculator", function (req, res) { heigh = parseFloat(req.body.Height); weigh = parseFloat(req.body.Weight); bmi = weigh / (heigh * heigh); //number to string format bmi = bmi.toFixed(); req_name = req.body.Name; // CONDITION FOR BMI if (bmi < 19) { res.send("<h3>hey! " + req_name + " your BMI is around: " + bmi + "<centre><h1>You are Underweight!"); } else if (19 <= bmi && bmi < 25) { res.send("<h3>hey! " + req_name + " your BMI is around: " + bmi + "<centre><h1>You are Normalweight!"); } else if (25 <= bmi && bmi < 30) { res.send("<h3>hey! " + req_name + " your BMI is around: " + bmi + "<centre><h1>You are Overweight!"); } else { res.send("<h3>hey! " + req_name + " your BMI is around: " + bmi + "<centre><h1>You are Obese!"); } }); //this is used to listen a specific port! app.listen(7777, function () { console.log("port active at 7777"); }); Output:   Final Output:  Output  Comment More infoAdvertise with us Next Article BMI Calculator using Express.js R rahulmahajann Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Express.js Technical Scripter 2020 NodeJS-Questions +2 More Similar Reads BMI Calculator Using React In this article, we will create a BMI Calculator application using the ReactJS framework. A BMI calculator determines the relationship between a person's height and weight. It provides a numerical value that categorizes the individual as underweight, normal weight, overweight, or obese.Output Previe 3 min read Design a BMI Calculator using JavaScript A BMI (Body Mass Index) Calculator measures body fat based on weight and height, providing a numerical value to categorize individuals as underweight, normal weight, overweight, or obese. Itâs widely used to assess health risks and guide lifestyle or medical decisions.A BMI Calculator using JavaScri 3 min read Create a Calculator App Using Next JS Creating a Calculator app is one of the basic projects that clears the core concept of a technology. In this tutorial, we'll walk you through the process of building a calculator app using Next.js. Output Preview: Let us have a look at how the final output will look like. Prerequisites:NPM & Nod 3 min read Calculator App Using TypeScript A calculator app is a perfect project for practising TypeScript along with HTML and CSS. This app will have basic functionalities like addition, subtraction, multiplication, and division. It provides a clean and interactive interface for the user while using TypeScript to handle logic safely and eff 6 min read BMI Calculator Card using Tailwind CSS & JavaScript The Body Mass Index (BMI) Calculator can be used to calculate BMI values based on height and weight. BMI is a fairly reliable indicator of body fatness for most people. In this article, we will implement a BMI (Body Mass Index) Calculator using JavaScript with Tailwind CSS framework. Formula to calc 3 min read Like