Express Validator Error: expressValidator is not a function

前端 未结 6 1135
孤街浪徒
孤街浪徒 2020-12-16 17:57

I\'m trying to install and use express-validator package. I\'ve installed the package version (6.0.0) and then in my server.js file the code is:

const bodyPa         


        
6条回答
  •  被撕碎了的回忆
    2020-12-16 18:46

    const { check, validationResult } = require('express-validator');
    router.post('/finished', function (req, res) {
    let email = req.body.email
    
    check('email', 'Email required').isEmail()
    
    var errors = validationResult(req)
    if (errors) {
      req.session.errors = errors
      req.session.success = false
      res.redirect('/email-adress')
      } else {
      req.session.success = true
      res.redirect('/finished')
      }
    })
    

    Do this. And remove

    app.use(expressValidator()) 
    

    line.

提交回复
热议问题