- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
TypeError: req.checkBody is not a function
at C:\techscape\nodeauth\routes\users.js:41:7
at Layer.handle [as handle_request] (C:\techscape\nodeauth\node_modules\express\lib\router\layer.js:95:5)
at next (C:\techscape\nodeauth\node_modules\express\lib\router\route.js:137:13)
at Array.<anonymous> (C:\techscape\nodeauth\node_modules\multer\lib\make-middleware.js:53:37)
at listener (C:\techscape\nodeauth\node_modules\on-finished\index.js:169:15)
at onFinish (C:\techscape\nodeauth\node_modules\on-finished\index.js:100:5)
at callback (C:\techscape\nodeauth\node_modules\ee-first\index.js:55:10)
at IncomingMessage.onevent (C:\techscape\nodeauth\node_modules\ee-first\index.js:93:5)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
代码:
var express = require('express');
var router = express.Router();
var multer=require('multer');
var upload=multer({dest:'./uploads'});
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
router.get('/login', function(req, res, next) {
res.render('login');
});
router.get('/signup', function(req, res, next) {
res.render('signup');
});
router.post('/signup',upload.single('profileimg'), function(req, res, next) {
// console.log(req.body.username);
// console.log(req.body.email);
// console.log(req.body.password);
// console.log(req.body.password2);
// console.log(req.file);
var username=req.body.username;
var email=req.body.email;
var pass=req.body.password;
var pass2=req.body.password2;
//var file=req.file;
if(req.file){
console.log("uploading file ");
var image=req.file.filename;
}else{
console.log("NO files uploaded ");
}
//Validators
req.checkBody('username','UserName is required').isEmpty();
// req.checkBody('email','email is Required').isEmail();
// req.checkBody('password','Passwrd is required').isEmpty();
// req.checkBody('password2','email is Required').equal(req.password);
});
router.post('/login', function(req, res, next) {
var username=req.body.username;
var password=req.body.pass;
// console.log(req.body.username);
// console.log(req.body.pass);
});
enter code here
module.exports = router;
最佳答案
req.checkBody()
不是标准的 ExpressJS 函数。
这是 express-validator 提供的功能模块。
您需要先安装它:
$ npm i 快速验证器
然后引用它:
var express = require('express');
var expressValidator = require('express-validator');
var router = express.Router();
router.use(expressValidator());
// ...
关于node.js - req.checkBody 不是一个函数,我需要解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52219375/
我正在按照 Mozilla Express 教程 (https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/
我正尝试在注册系统中实现一些验证,但出现错误: TypeError: req.checkBody is not a function 来自以下代码: module.exports = fun
我已经尝试解决这个问题 2 个小时了,但我有点沮丧。基本上,我想验证表单输入,但我总是收到此错误。 TypeError: req.checkBody is not a function at C:\U
TypeError: req.checkBody is not a function at C:\techscape\nodeauth\routes\users.js:41:7 at
我在使用快速验证器时遇到问题,特别是 isDate 函数。我已经采取措施使用 expressvalidator、bodyparse、validator 模块等。所有路由仅在此之后..环境是 Node
在nodejs中我们通常会做这样的事情: req.checkBody('name', 'Group name is required.').notEmpty(); 同样,我也做了这样的事情: req.
我是一名优秀的程序员,十分优秀!