TypeError:res.res.sent不是一个函数

我不知道为什么会出现这个问题,我尝试了很多方法,但没有任何效果,我的 Express 已安装并更新,所以我不知道是什么导致了这个问题


const express = require("express");

const bodyParser = require("body-parser");

const app = express();


app.use(bodyParser.urlencoded({extended: true}));

app.get("/", function(req, res){

  res.sentFile(__dirname + "/index.html");

});

app.post("/", function(req, res){

  var weight = Number(req.body.weight);

  var height = Number(req.body.hight);

  var height2 = (height * height);

  var bmi = weight/height;

  res.sent("your bmi is " + bmi);


});

app.listen(3000, function(){

  console.log("server is live on port:3000");

}

);

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>bmi</title>

</head>

<body>

    <form action="/" method="POST">

    <input type="text" name="weight" placeholder="Enter your weight">

    <input type="text" name="height" placeholder="enter height">

    <button type="submit" name="submit">calculate</button>

    </form>

    

</body>

</html>

这是package.json


{

  "name": "my-express-server",

  "version": "1.0.0",

  "description": "",

  "main": "server.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1",

    "start": "node server.js"

  },

  "author": "muaaz",

  "license": "ISC",

  "dependencies": {

    "body-parser": "^1.19.0",

    "express": "^4.17.1"

  }

}


墨色风雨
浏览 86回答 1
1回答

跃然一笑

你需要改变res.sent和res.sentFileres.sendres.sendFile
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript