title: Get this error on project debugging the error is req.next is not a function
body: <p>I am working on a node js with express framework. Actually i am switching pug template engine to handlebars. On that time i stuck with this error.I make changes in app.js file to change the template engine. Please help me to resolve this issue.</p>
  
  <pre><code>/media/iron/1d6c195f-2350-423c-a3f0-0500c92e580a/admin-template/project/node_modules/express/lib/response.js:1003
      if (err) return req.next(err);
                          ^
  
  TypeError: req.next is not a function
      at done (/media/iron/1d6c195f-2350-423c-a3f0-0500c92e580a/admin-template/project/node_modules/express/lib/response.js:1003:25)
      at Immediate.&lt;anonymous&gt; (/media/iron/1d6c195f-2350-423c-a3f0-0500c92e580a/admin-template/project/node_modules/express-handlebars/lib/utils.js:18:13)
      at runCallback (timers.js:763:18)
      at tryOnImmediate (timers.js:734:5)
      at processImmediate (timers.js:716:5)
  </code></pre>
  
  <p>Node: v9.11.0</p>
  
  <p>Npm: 6:4:1
  App.js file code. Pug template engine code is commented and using handlebars code.</p>
  
  <pre><code>var createError = require('http-errors');
  var express = require('express');
  var app = express();
  var path = require('path');
  var cookieParser = require('cookie-parser');
  var logger = require('morgan');
  var mongoose = require('mongoose');
  var bodyParser = require("body-parser");
  var exphbs = require("express-handlebars");
  var session = require('express-session');
  var firebase = require("firebase-admin");
  var MongoStore = require('connect-mongo')(session);
  
  //connect to MongoDB
  mongoose.connect('mongodb://localhost/ForAuth',{ useNewUrlParser: true });
  var db = mongoose.connection;
  
  //handle mongo error
  db.on('error', console.error.bind(console, 'connection error:'));
  db.once('open', function () {
    //console.log('were connected!');
  });
  
  //use sessions for tracking logins
  app.use(session({
    secret: 'work hard',
    resave: true,
    saveUninitialized: false,
    store: new MongoStore({
      mongooseConnection: db
    })
  }));
  
  // parse incoming requests
  app.use(bodyParser.urlencoded({
      extended: true
  }))
  app.use(bodyParser.json());
  
  // view engine setup
  //app.set('views', path.join(__dirname, 'views'));
  //app.set('view engine', 'pug');
  
  app.set('views', path.join(__dirname, 'views'));
  app.engine('handlebars', exphbs({defaultLayout:'layout'}));
  app.set('view engine', 'handlebars');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  var indexRouter = require('./routes/index');
  var usersRouter = require('./routes/users');
  //var dashboardRouter = require('./routes/dashboard');
  
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  //app.use('/dashboard', dashboardRouter);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    next(createError(404));
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  module.exports = app;
  </code></pre>