場(chǎng)景:我的Express項(xiàng)目。數(shù)據(jù)庫(kù)操作和路由操作都放在入口文件(app.js)。并且相互之間耦合高。
問(wèn)題:我想把數(shù)據(jù)庫(kù)和路由模塊化或抽象為類 ,解耦。。求給個(gè)思路...
Use the Express application generator to create a project:
express myapp
Then you can write it in the routes directory, or you can build your own Controller
Express is sufficient for small projects, and Sails.js, a Fullstack framework, is recommended for large projects.
There are many demos on Github, such as: https://github.com/madhums/node-express-...
The directory structure I generally use: https://github.com/hstarorg/any-mock/tre...,
routes -> bizs -> (common and db)