找不到在heroku module.js中部署的解决方案:487 throw err; ^错误:找不到模块' Handlebars'

时间:2017-11-23 10:10:43

标签: node.js mongodb express heroku handlebars.js

app js code


module.js:487
    throw err;
    ^

Error: Cannot find module 'Handlebars'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/app/routes/usersInfo.js:6:20)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)




//global require extensions    

    const express = require('express');
    const path = require('path');
    //const hbs = require('Handlebars');
    const exphbs  = require('express-handlebars');
    //var session = require('express-session');
    const methodOverride = require('method-override');
    const flash = require('connect-flash');
    const session = require('express-session');
    const bodyParser = require('body-parser');
    const bcrypt = require('bcryptjs');
    const passport = require('passport');
    const mongoose = require('mongoose');

    //const  paginate = require('handlebars-paginate');
    const app = express();
    const email = require('email-validator');
    var globals = require('globals'); //<< globals.js path

    require('./models/User');
    require('./models/Assignment')
    require('./models/TimeSheet')
    const User = mongoose.model('users')
    const usersInfo = require('./routes/usersInfo');
    const users = require('./routes/users');
    const assignment = require('./routes/assignment');
    const timesheet = require('./routes/timesheet');
    require('./config/passport')(passport);
    //db config
    const db=require('./config/database');
    mongoose.Promise = global.Promise;
    global.autoincrement = 0;

   //mongo connection

mongoose.connect('mongodb://venu:venu@ds117156.mlab.com:17156/tidrapportering',{useMongoClient:true})
    .then(()=> console.log('MongoDB Connected..'))
    .catch(err=>console.log(err));

    const {ensureAuthenticated,select} = require('./helpers/auth');
    //Load users model
    //require('./models/Users');
    //const User = mongoose.model('Users')

     app.engine('handlebars',exphbs({ helpers: {

         select:select

      },defaultLayout:'main'}));
     app.set('view engine','handlebars');

    // Body parser middleware
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(bodyParser.json());

    // Static folder
    app.use(express.static(path.join(__dirname, 'public')));

    // Method override middleware
    app.use(methodOverride('_method'));

    // Express session midleware
    app.use(session({
      secret: 'secret',
      resave: true,
      saveUninitialized: true
    }));

    // Passport middleware
    app.use(passport.initialize());
    app.use(passport.session());

    app.use(flash());

    // Global variables
    app.use(function(req, res, next){
        res.locals.success_msg = req.flash('success_msg');
        res.locals.error_msg = req.flash('error_msg');
        res.locals.error = req.flash('error');
        res.locals.accessadmin = false;
        res.locals.accessuser = false;
        res.locals.accessassistant =false;
        res.locals.access = 'user';
        res.locals.logout = false;
        res.locals.user = req.user || null;
        next();
      });



    app.get('/',(req, res)=>{
        const title='Welcome2';
      res.locals.logout = true;
        User.findOne({email:'admin@simplegrowth.se'})
        .then(user=>{
                if(user){

                        req.flash('error_msg','');
                        res.redirect('/users/login');

                }else{
        const newUser=new User({
            name :'Admin',
            email: 'admin@simplegrowth.se',
            password:'admin',  
            accesslevel: 'admin'    });
    bcrypt.genSalt(10,(err,salt)=>{
        bcrypt.hash(newUser.password, salt,(err,hash)=>{
            if(err) throw err;
            newUser.password = hash;
            newUser.save()
            .then(user=>{
                req.flash('success_msg', 'Admin created successfully.');
                res.redirect('/users/login');
            })
            .catch(err=>{console.log(err);
            return;
            });
        });

    });
                }
        //res.render('index',{title:title});
    });
    });
    app.get('/About',(req,res)=>{
    res.render('About');
    });







    // have it listen on 8080

    // Use routes
    app.use('/users', users);
    app.use('/usersInfo', usersInfo);
    app.use('/assignment',assignment);
    app.use('/timesheet',timesheet);
    //app.use('/users', users);
    const port = process.env.PORT||3443

      app.listen(port,()=>{
           console.log(`Server started on port ${port}`);
      });


//  this is only the app.js code but i am getting error while deploying in heroku and on click of open app in logs i am finding error mentioned above

0 个答案:

没有答案