NodeJs错误:未指定默认引擎且未提供扩展名-不使用res.render

时间:2019-12-27 00:57:41

标签: node.js api post nodes

    /* Add User */
router.post('/addUser', function(req, res, next) {
var matrikel_number = req.body.matrikel_number;
// var first_name = req.body.first_name;

var username = req.body.username;
var password = bcrypt.hashSync(req.body.password, 10);
var sql = `INSERT INTO users (matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, role_id, username, password)
SELECT matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, '1', ${username}, ${password}
FROM student_archives 
WHERE matrikel_number = ${matrikel_number}`
db.query(sql, function(err, row, fields) {
    if (err) {
        res.status(500).send({error: 'Something went wrong!'})
    }
        res.status(200).send('Success');
    })
});

SQL运行正常,突然开始出现此引擎错误。我不知道为什么需要帮助。

2 个答案:

答案 0 :(得分:0)

如果您的代码中包含这一行,请删除此内容。

app.set('views', path.join(__dirname, 'views'));

为了渲染视图,必须有一些引擎... 像app.set('view engine', 'pug'); 你还没有指定。

答案 1 :(得分:0)

        /* Add User */
       router.post('/addUser', function(req, res, next) {
var matrikel_number = req.body.matrikel_number;
var role_id = 1
var username = req.body.username;
var password = bcrypt.hashSync(req.body.password, 10);
var sql = `INSERT INTO users (matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, role_id, username, password) 
SELECT matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, '${role_id}', '${username}', '${password}' 
FROM student_archives 
WHERE matrikel_number = ${matrikel_number}`
db.query(sql, function(err, rows, fields) {
    if (!err) {
        res.status(200).send('Success');
        return false;
    }
    res.status(500).send({error: 'Something went wrong, please try again!'});
})
});

我进行了上述更改,并且有效。谢谢大家的帮助。