不加载“express-validator”:迁移到Express 3

包含“express-validator”的我还没有完成加载的应用程序,显然是我定义,使用或调用的位置是不正确的,正如对此问题的评论中所build议的。

这是我的app.js的一部分,感谢所有的build议:

var express = require('express') , expressValidator = require('express-validator') , routes = require('./routes') , http = require('http') , path = require('path'); 

 var app = express(); app.set('port', process.env.PORT || port); app.set('views', __dirname + '/views'); app.engine('.html', require('ejs').renderFile); app.set('view engine', 'html'); app.use(express.logger('dev')); app.use(express.bodyParser()); // The problem app.use(expressValidator); app.use(express.methodOverride()); app.use(express.static(path.join(__dirname, 'public'))); app.use(express.cookieParser()); app.use(express.session({ secret: 'keyboard test' })); app.use(function(req, res, next){ var err = req.session.error , msg = req.session.success; delete req.session.error; delete req.session.success; res.locals.message = ''; if (err) res.locals.message = '<p class="msg error">' + err + '</p>'; if (msg) res.locals.message = '<p class="msg success">' + msg + '</p>'; next(); }); app.use(app.router); 

 app.post('/login', function(req, res){ req.assert('email', 'Range email').len(6, 40); req.assert('password', 'Range password').len(6, 20); var errors = req.onValidationError(); if(errors.length == 0) { 

       

网上收集的解决方案 "不加载“express-validator”:迁移到Express 3"