Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:TypeError:Undefined在迁移到Express 4.12.1时不是函数)_Javascript_Node.js_Express - Fatal编程技术网

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

Javascript 错误:TypeError:Undefined在迁移到Express 4.12.1时不是函数),javascript,node.js,express,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.

所以我有一段代码:

  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());
但是,当我尝试使用节点编译它时,出现了此错误: “this.engine('ejs',require('ejs-locals')); TypeError:未定义不是函数“


那么,如何才能毫无问题地删除“app.configure()”部分呢

请尝试
app.something
,而不是
this.something
,等等。非常感谢,它成功了。但是这一行也发生了同样的错误:sockets.authorization(函数(handshakeData,callback){节点的箭头指向“authorization”的“a”。这是因为您的
sockets
变量没有方法
authorization
。请尝试检查您是如何设置的。Express 4.12.1没有app.configure功能。请检查文档的