Playing around with Node.js and I really want to keep开发者_如何学Go my file structure organized. Normally in a project in another language I would have a structure like this:
- Node App Directory
- App.js
- Controllers
- UserController.js
- OtherController.js
- Models
- UserModel.js
- OtherModel.js
The (potential) problem I see is this: I use Mongoose and MongoDB for my database, in order to define a "Model" I need a Mongoose Schema, in order to do that I have to connect to the database with Mongoose in each of the Controllers and Model files.
I know so little about these technologies, this could be lightning quick and never be an issue and I wouldn't have a clue. Or is this something I should avoid and just shove everything in one (very large) file?
You don't need to connect to mongo in every controller/model file. Just do it once in App.js
and you're done.
精彩评论