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功能。请检查文档的