错误:TypeError:Undefined不是函数迁移到Express 4.12.1时)

时间:2015-05-04 16:35:44

标签: javascript node.js express

所以我有这段代码:

  app.configure(function() {
  this.engine('ejs', require('ejs-locals'));
  this.set('views', path.join(__dirname, 'views'));
  this.set('view engine', 'ejs');
  this.use(express.static(path.join(__dirname, '/public')));
  this.use(express.static(path.join(__dirname, '/views/login')));
  this.use(express.static(path.join(__dirname, '/views/elyes')));
  // Allow parsing cookies from request headers
  this.use(express.cookieParser());

  this.use(express.session({ "secret": sessionSecret, "store": sessionStore }));
  // Allow parsing form data
  this.use(express.bodyParser());
});

我已将其更改为此代码,因为我必须删除app.configure()才能使用Express 4运行它:

  this.engine('ejs', require('ejs-locals'));
  this.set('views', path.join(__dirname, 'views'));
  this.set('view engine', 'ejs');
  this.use(express.static(path.join(__dirname, '/public')));
  this.use(express.static(path.join(__dirname, '/views/login')));
  this.use(express.static(path.join(__dirname, '/views/elyes')));
  // Allow parsing cookies from request headers
  this.use(cookieparser());

但是当我尝试使用Node编译它时发生了这个错误: " this.engine(' ejs',要求(' ejs-locals')); TypeError:undefined不是函数"

那么如何删除" app.configure()"部分没有问题?

0 个答案:

没有答案