node.js - Express NodeJS 找不到模块 'html'

标签 node.js express

我有一个带有 Express 的 Node 服务器。尽管我的代码看起来像这样并且在我看来应该是正确的,但我收到了无法找到模块“html”错误:

app.set('views', path.join(__dirname, 'build/views'));
app.use(favicon(path.join(__dirname, "build/favicon.ico")));
app.use('/scripts', express.static(path.join(__dirname, 'node_modules')));
app.use(express.static(path.join(__dirname, 'build')));

app.get('/', function(req, res){
    res.render('index.html');
});

最佳答案

您必须为 HTML 设置引擎

将此代码包含在您的主文件中

var engines = require('consolidate');

app.engine('html', engines.mustache);
app.set('view engine', 'html');

关于node.js - Express NodeJS 找不到模块 'html',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39506787/

相关文章:

javascript - 检测 Node 是否接收标准输入

node.js - Promisify Node 模块上的所有子方法

node.js - 为什么在编辑状态码时没有正确表达重定向

express - 谷歌 Passport 回调后设置cookie

javascript - TS2307 : Cannot find module '~express/lib/express'

node.js - nodejs表达本地ip地址

AngularJS NodeJS HTTPS 请求

javascript - then() 回调在 node.js 中解析之前触发

node.js - MissingSchemaError : Schema hasn't been registered for model, mongoose.model 在模式之前调用

node.js - sequelize 是否有自动迁移的工具?