Express JS render:TypeError:this.engine不是一个函数 [英] Express js render : TypeError: this.engine is not a function

查看:31
本文介绍了Express JS render:TypeError:this.engine不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到TypeError:this.engine不是函数.我不知道为什么会收到此错误.谁能帮我解决这个问题.

I am getting TypeError: this.engine is not a function. I don`t know why I am getting this error. Can anyone please help me to solve this issue.

我的服务器文件:

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文件:

And my HTML file:

<!DOCTYPE html>
<html>

<head>

</head>

<body>
    <div>Hello Express</div>
</body>

</html>

我得到了错误

我的package.json:

My 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": ""
}

我通过


npm install --save html

推荐答案

html 程序包与Express无关.因此,如果您告诉Express使用它,它就会失败.

The html package you've installed is unrelated to Express. So it's not surprising that if you tell Express to use it, it fails.

如果您希望提供静态HTML文件,请参见快递文档.最简单的方法就是

If you're looking to serve static HTML files, see this question's answers, and the Express documentation. The simplest way is just

app.use(express.static('views'));

这篇关于Express JS render:TypeError:this.engine不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆