node.js - 防止 Express 向 Jade 模板显示错误

标签 node.js express pug

我不确定如何防止这种情况,如果我的 Jade 模板出现错误,即使在产品中也会显示在前端。

enter image description here

如何防止这种情况发生?

最佳答案

您可以处理错误,而不是默认行为(将错误发送到客户端)。使用回调并检查错误。如果有任何错误,则不要显示它们,而是显示如下错误页面。

 res.render(your_template, {}, function(err, html) {
        if(err) {
            res.redirect('/error');
        } else {
            res.send(html);
        }
    });

引用号:How do I turn off Node.js Express (ejs template engine) errors for production?

关于node.js - 防止 Express 向 Jade 模板显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45850807/

相关文章:

node.js - 如何为开发和部署组织单独的客户端和服务器存储库?

node.js - Redis Cloud 和 connect-redis : the client is closed

node.js - 为 Node.js 重写 PHP URL

javascript - 广播到房间的套接字 IO 无法正常工作

javascript - 防止浏览器记住凭据(密码)

node.js - 如何使用 Nodejs 在 Express-validator 中验证 multipart/form-data

javascript - Angular 4 ngFor

javascript - 如何在 node.js 中执行此 curl 操作

mysql - 有人用Node.JS更新MySQL吗

pug - 在 Pug 中添加事件导航链接类