[英]Why I'm getting ERR_HTTP_INVALID_STATUS_CODE?
I am making a simple calculator that does calculation on server as a beginner project.我正在制作一个简单的计算器,作为初学者项目在服务器上进行计算。 This is the code I have written in
.js
file:这是我在
.js
文件中编写的代码:
const express = require("express");
const bodyParser=require("body-parser");
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});
app.post("/",function(req,res){
var num1=Number(req.body.num1);
var num2=Number(req.body.num2);
var num3=num1+num2;
res.send(num3); // gives error if i don't write it as string >>like
//res.send("your answer is"+num3); >> this one doesn't throw an error
})
app.listen(3001, function () {
console.log("server started at port 3001");
});
Why is this so?为什么会这样? I am a beginner so please explain simply.
我是初学者,请简单解释一下。
This problem is happening because you are giving send
a parameter which is a Number
, that isn't supported by the method.发生此问题是因为您
send
了一个Number
参数,该方法不支持该参数。 Here is what the doc says:这是文档所说的:
res.send([body])
res.send([正文])
The
body
parameter can be aBuffer
object, aString
, anObject
,Boolean
, or anArray
.body
参数可以是Buffer
object、String
、Object
、Boolean
或Array
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.