【发布时间】:2017-09-26 08:02:47
【问题描述】:
我收到 TypeError:this.engine 不是函数。我不知道为什么会收到此错误。谁能帮我解决这个问题。
我的服务器文件:
var express = require('express');
var path = require('path');
var app = express();
//configure app
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));
app.get('/', function (req, res) {
res.render('index');
});
app.listen(3000, function() {
console.log('Ready on port 1337');
});
还有我的 HTML 文件:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>Hello Express</div>
</body>
</html>
我得到了错误
我的 package.json:
{
"name": "app",
"version": "1.0.0",
"main": "index.html",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "mehadi",
"license": "UNLICENSED",
"dependencies": {
"express": "4.13.0",
"html": "^1.0.0"
},
"repository": {
"type": "git",
"url": "(github.com/mehadi07/Random.git)"
},
"devDependencies": {},
"description": ""
}
我通过
安装了html 引擎
npm install --save html
【问题讨论】:
-
你的
package.json是什么?你在哪里注册这个'html'视图引擎,你在注册什么引擎? -
您尝试使用什么模板引擎?我不认识
html-template 引擎。您是否安装了引擎(使用npm)?请RTFM:expressjs.com/en/guide/using-template-engines.html -
{ "name": "app", "version": "1.0.0", "main": "index.html", "directories": { "test": "test" } , "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "mehadi", "license": "UNLICENSED", "dependencies": { "express ": "4.13.0", "html": "^1.0.0" }, "repository": { "type": "git", "url": "(github.com/mehadi07/Random.git)" }, "devDependencies": {}, "描述": "" }
-
我使用了 npm install --save html
-
@MdMehadiHasanMozumder:要改进问题、添加详细信息等,请使用“编辑”链接,而不是 cmets。