im new and still learning, my project is to make a BMI calculator using node.js, js, HTML.. when i run my code it works no problem on the webpage except when i try to calculate i end up with this error.
i have looked online but i couldnt understand or solve my problem. thank you in advanced for any help.
MINGW32 ~/Desktop/Calculator
$ nodemon calculator.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node calculator.js`
calc server started!!!
TypeError: Cannot read property 'weight' of undefined
at C:\Users\pc\Desktop\Calculator\calculator.js:30:38
at Layer.handle [as handle_request] (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\index.js:275:10)
at expressInit (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (C:\Users\pc\Desktop\Calculator\node_modules\express\lib\router\layer.js:95:5)
in my file for calculator.js
/*eslint-env es6*/ // Enables es6 error checking for that file
/*eslint-env jquery*/ // Enables error checking for jquery functions
/*eslint-env browser*/ // Lets you use document and other standard browser functions
/*eslint no-console: 0*/ // Lets you use console (for example to log something)
//jshint esversion:6
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.get(bodyParser.urlencoded({extended: true}));
//app.get("/",function(req, res){
// res.sendFile(__dirname+"/index.html");
//});
//app.post("/",function(req,res){
// var n1 = Number(req.body.n1);
// var n2 = Number(req.body.n2);
// var result = n1 + n2;
//
// res.send("The result of the calculation is "+ result);
//});
app.get("/bmicalculator",function(req, res){
res.sendFile(__dirname+"/bmiCalculator.html");
});
app.post("/bmicalculator", function(req, res){
var weight = parseFloat(req.body.weight);
var height = parseFloat(req.body.height);
var bmi = weight / (height * height);
res.send("Your BMI is " + bmi);
});
app.listen(1990, function(){
console.log("calc server started!!!");
});