在post.js中,我有以下内容:
const express = require('express');
const validator = require('../validator');
const router = express.Router();
const { check, validationResult } = require('express-validator');
router.post("/post", validator.myValidator);
module.exports = router;
在validator / index.js中,我有:
exports.myValidator = (req, res, next) => {
req.check('username', 'Username field is required').notEmpty();
const errors = req.validationResult();
:
}
我想将post.js中的check和validateResult方法传递给index.js中的myValidator,以便我可以在index.js中执行验证。我正在使用Express-validator版本6.5.0。