red_student red_student - 3 months ago 16
Node.js Question

Cannot find module '/auth'

I am trying to authenticate users with the Facebook passport strategy and am running into a problem where I am unable to load my auth/passport.js files. Here is my code:

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());
...


It says that it cannot find the node module './auth', even though it is at the same directory level as the app.js. My directory is:

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


Any ideas?

Answer

Since there is no index.js file inside your auth/ directory, you have to specify which file you want to load (e.g. require('./auth/auth') or require('./auth/passport')).

Comments