1
我試圖在調用原始app.get之前完成一些工作。Expressjs ejs fn.apply錯誤'查看不是構造函數'
我找到了this頁面,我嘗試了他們所做的工作,它主要工作,期望當我嘗試使用它的渲染引擎時。
我使用(app
是express()
結果)代碼:
const express = require('express');
const app = express();
const ejs = require('ejs');
app.set('view engine', 'ejs');
var originalfoo = app.get;
app.get = function() {
// Do stuff before calling function
console.log(arguments);
// Call the function as it would have been called normally:
originalfoo.apply(this, arguments);
// Run stuff after, here.
};
app.get('/home', function (req, res) {
//res.send('hello world') // This works
res.render('index'); // This crashes
});
res.render給了我這個錯誤:TypeError: View is not a constructor
有誰知道我怎麼能解決這個問題?
PS:/views/index.ejs
確實存在
這確實奏效了! 非常感謝! – CreasolDev