我无法让这段非常基本的代码在新版本中工作。这是我的代码
const express = require("express");
const bodyParser = require("body-parser");
const validator = require("express-validator");
const { check, validationResult } = require("express-validator/check");
const app = express();
app.use(bodyParser.json());
app.use(validator());
app.post('/',
[ check("email").isEmail() ],
(req, resp) => {
const errors = validationResult(req);
resp.send(errors.mapped()); });
app.listen(3000, () => { console.log('listening on port 3000'); });
我发送了一个包含正文的发布请求:
{ "email": "ha@gmail.com" }
即使我提供的电子邮件完全正确,响应总是错误
{ "email": { "location": "body", "param": "email", "msg": "Invalid value" } }
我错过了什么吗?