Error: No default engine was specified and no extension was provided.

Error: No default engine was specified and no extension was provided.

When the above error occurs when using art-template in express, the error code is as follows:

//引入express
const express = require('express');
// 数据存储
const mongoose = require('mongoose');

// 创建服务
const app = express();

// 配置模板引擎
app.engine('html',require('express-art-template'));

app.get('/',(req,res) => {
    
    
    res.render('mongodb_test',{
    
     // 出错点
        users:[{
    
    
            id: 1,
            uname: 'zt',
            sex: '男',
            age: 18
        }]
    })
})

// 监听服务
app.listen(3000,() => {
    
    
    console.log('server is running...');
})

The reason for the error: The mongodb_test file cannot be found. Solution: You need to add a suffix to the file .html, that is:, mongodb_test.htmlReason: Although the template engine is configured to htmlwork on the ending file, when you look for this file, It is searched together according to the given file nouns including the file suffix, and it will not be found.

Guess you like

Origin blog.csdn.net/chen__cheng/article/details/114943778