2016-09-01 233 views
0

我正嘗試使用Facebook護照策略驗證用戶,並且遇到了無法加載我的auth/passport.js文件的問題。這裏是我的代碼:找不到模塊'/ auth'

app.js

var express = require('express'); 
var path = require('path'); 
var favicon = require('serve-favicon'); 
var logger = require('morgan'); 
var cookieParser = require('cookie-parser'); 
var bodyParser = require('body-parser'); 
var passport = require('passport'); 
var routes = require('./lib/routes/index'); 
var users = require('./lib/routes/users'); 
var session = require('express-session'); 
var app = express(); 

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

require('./auth')(passport); 
app.use(session({secret :'sample'})); 
app.use(passport.initialize()); 
app.use(passport.session()); 
... 

它說,它無法找到節點模塊「./auth」,即使是在同一目錄級別的app.js 。我的目錄是:

app.js 
auth/ 
    auth.js 
    passport.js 
src/ 
    routes/ 
     authenticatedRoutes.js 

任何想法?

回答

0

由於auth /目錄中沒有index.js文件,因此必須指定要加載的文件(例如,require('./auth/auth')require('./auth/passport'))。

0

您直接嘗試使用var auth=require('./auth/passport');auth.js相同