0

"bodyParser" is deprecated, Node.js

Hello, I am new to backend, I was just trying to make my first web app(BMI Calculator), and faced my first obstacle on the way... Here is my js code const express = require('express'); const bodyParser = require('body-parser'); const app = express(); app.use(bodyParser.urlencoded({extended: true})); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); app.post('/', function(req, res){ var height = parseInt(req.body.height); var weight = parseInt(req.body.weight); var bmi = Math.floor((body/(height*height))*10)/10; res.send("Your BMI is " + bmi + "."); }); app.listen(3000, function(req, res){ console.log("server is running on port 3000"); }); and here is my html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>BMI Calculator</title> </head> <body> <h1>BMI Calculator</h1> <form action="/" method="post"> <input type="text" name="height" placeholder="Enter your heigt here"> <input type="text" name="weight" placeholder="Enter your weight here"> <button type="submit">Submit</button> </form> </body> </html> So, before submitting value, everything was going well, but when I submitted it, got "ReferenceError: body is not defined" this error in terminal. please need help

20th Sep 2021, 9:04 AM
Satyam Das
Satyam Das - avatar
1 Antwort
0
Looks like bodyParser is deprecated . Instead you can use express.urlencoded({extended:true}).
20th Sep 2021, 9:23 AM
Abhay
Abhay - avatar