node.js - Express cannot find module -
i'm trying create login using passport in mean stack. i'm loading modules required setup passport stops working on 1 line of code. use express framework.
when start server gives me following error:
error: cannot find module './models/user'
this 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 mongoose = require('mongoose'); mongoose.promise = global.promise; mongoose.connect('mongodb://localhost/homeapp'); var passport = require('passport'); var localstrategy = require('passport-local').strategy; var index = require('./routes/index'); var users = require('./routes/users'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); // uncomment after placing favicon in /public //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: false })); app.use(cookieparser()); app.use(require('express-session')({ secret: 'designer cat', resave: false, saveuninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); var user = require('./models/user'); passport.use(new localstrategy(user.authenticate())); passport.serializeuser(user.serializeuser()); passport.deserializeuser(user.deserializeuser()); app.use(express.static(path.join(__dirname, 'public')));
folder structure:
├── app.js ├── bin │ └── www ├── package.json ├── models │ └── users.js ├── node_modules ├── public │ ├── images │ ├── javascripts │ └── stylesheets │ └── style.css ├── routes │ ├── index.js │ └── users.js └── views ├── error.jade ├── index.jade └── layout.jade
change var user = require('./models/user');
var user = require('./models/user');
your folder structure shows user model uppercase.
Comments
Post a Comment