node.js与快递 – 显示自定义错误消息

我正在使用node.js和expression,我想显示自定义错误信息,当找不到请求的页面。 目前我正在通过使用通配符。 如果有任何路线不匹配,则调用最后一个路线。 有没有其他更好的方法来做到这一点?

我的路线

app.get('/', routes.index); app.get('/users', user.list); app.get('/hello', hello.hello); app.get('/*', error.error); 

你在做什么是好的。 我唯一要改变的就是这样的路线顺序

  app.get('/users', user.list); app.get('/hello', hello.hello); app.get('/', routes.index); app.get('/*', error.error); 

遵循的一个好规则是首先定义所有最less的一般路线。 正如你可能知道这基本上告诉明白,如果没有其他路线被发现显示错误消息和通配符是一个很好的方法来做到这一点。