不玩不知道,一玩吓一跳,还真是,nodejs全局404怎么搞?

直接,res.render("404.html")有可能会报错:Node.js : Cannot find module html 那怎么解决呢?

答案:

如果你使用的是jade模板,则可以在views文件夹下面新增一个404.jade文件,里面引入一下你写好的404.html就可以了。

404.jade如下,就一行代码

include ../public/404.html 

404.html在public下面,随便发挥吧,html,随便写

就是普通的html

app.js

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  res.render('404');
  next(err); 
});

demo: http://ae6623.cn/404
http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2021-05-15
  • 2021-10-26
  • 2022-03-11
  • 2021-06-25
  • 2021-07-19
猜你喜欢
  • 2021-07-11
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
相关资源
相似解决方案