How to structure my nodejs code? fat model / skinny controller How to structure my nodejs code? fat model / skinny controller mongoose mongoose

How to structure my nodejs code? fat model / skinny controller


You can create a separate file under models or functions, where you can do all your model based processing related to "topSearch" and then simply call a single method inside of your controller.

Use something like async.js to better handle callbacks and flow.

I personally follow the folder structure defined in this repo.

better-node-express-app-structure

And sometimes I add subfolders into models and controllers depending on the complexity.

Frequently used select queries can be directly exported as independent functions to facilitate reusability.