看了Node.js开发指南发现routes和app.js分开的话要使用下面代码

app.use(express.router(routes)) 

但是真正是使用上面代码会遇到无数的问题报错

找了资料才发现express3.X不支持那个了

后来使用

routes(app);

index.ejs随之变成

/*
 * GET home page.
 */
module.exports=function(app){

  app.get('/',function(req,res){
    res.render('index',{
      title:'首页'
    });
  });
//.......其它配置
};

这就达到了routes和app.js的分离

相关文章:

  • 2021-08-24
  • 2021-12-10
  • 2021-06-13
  • 2021-08-02
  • 2021-08-26
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2021-11-18
  • 2021-06-10
  • 2021-07-15
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案