我在我的应用程序中使用护照进行身份验证。当我尝试初始化护照时,我收到了一个错误。我正在使用express来构建我的应用程序。我有corr
这是我的app.js文件 app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
var login = require('./routes/login');
var bodyParser = require('body-parser');
var app = express();
var db = require('./db.js');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var fetch = require('./routes/collect');
var passport = require('passport');
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/users', user.list);
app.get('/login',login.user);
app.get('/collect',fetch.collect);
app.post('/auth', urlencodedParser, auth.authentication);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
我收到此错误
app.use(passport.initialize());
^
TypeError: Object #<Object> has no method 'initialize'
at Object.<anonymous> (/home/kurakar/workspace/mywork/app.js:26:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
我在./routes/auth.js
文件中正确定义了护照模块。
的 PS:
当我使用npm install --save passport
和npm install --save passport-local
安装护照和本地护照时,它只显示以下行:
passport@0.2.1 node_modules/passport
├── passport-strategy@1.0.0
└── pause@0.0.1
passport-local@1.0.0 node_modules/passport-local
└── passport-strategy@1.0.0