Passport-Mongo,无法阅读属性&to toLowerCase'未定义的

时间:2016-08-05 18:58:50

标签: node.js mongodb mongoose exit passport.js

我正在尝试学习Node Js,Passport验证系统。我正在学习本教程:

http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619

我收到错误'无法读取属性' toLowerCase'未定义的'在npm开始。

由于我没有在代码中看到任何toLowerCase函数,所以我不明白这个错误是什么。

这是我的package.json:

  {
    "name": "passport-mongo",
    "version": "0.0.1",
    "private": true,
    "scripts": {
    "start": "node ./bin/www"
   },
    "dependencies": {
      "express": "~4.2.0",
      "static-favicon": "~1.0.0",
      "morgan": "~1.0.0",
      "cookie-parser": "~1.0.1",
      "body-parser": "~1.0.0",
      "express-session": "~1.0.4",
      "debug": "~0.7.4",
      "jade": "~1.3.0",
      "passport": "~0.2.0",
      "passport-local": "~1.0.0",
      "mongodb": "^2.1.16",
      "mongoose": "^4.4.12",
      "bcrypt-nodejs" : "*",
      "connect-flash" : "*"
    }
     }

这是app.js

var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var dbConfig = require('./db.js');
var mongoose = require('mongoose');
// Connect to DB
mongoose.connect(dbConfig.url);

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Configuring Passport
var passport = require('passport');
var expressSession = require('express-session');
// TODO - Why Do we need this key ?
app.use(expressSession({secret: 'mySecretKey'}));
app.use(passport.initialize());
app.use(passport.session());

 // Using the flash middleware provided by connect-flash to store messages in session
 // and displaying in templates
var flash = require('connect-flash');
app.use(flash());

// Initialize Passport
var initPassport = require('./passport/init');
initPassport(passport);

var routes = require('./routes/index')(passport);
app.use('/', routes);

/// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

module.exports = app;

1 个答案:

答案 0 :(得分:0)

C:\Projects!\Login3\passport-mongo>npm start

> passport-mongo@0.0.1 start C:\Projects!\Login3\passport-mongo
> node ./bin/www

C:\Projects!\Login3\passport-mongo\node_modules\express\lib\router\index.js:116
  var method = req.method.toLowerCase();
                         ^

TypeError: Cannot read property 'toLowerCase' of undefined
    at Function.proto.handle (C:\Projects!\Login3\passport-mongo\node_modules\express\lib\router\index.js:116:26)
    at router (C:\Projects!\Login3\passport-mongo\node_modules\express\lib\router\index.js:24:12)
    at Object.<anonymous> (C:\Projects!\Login3\passport-mongo\app.js:44:39)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Projects!\Login3\passport-mongo\bin\www:7:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.4.4
npm ERR! npm  v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! passport-mongo@0.0.1 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the passport-mongo@0.0.1 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the passport-mongo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs passport-mongo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls passport-mongo
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Projects!\Login3\passport-mongo\npm-debug.log

C:\Projects!\Login3\passport-mongo>