As I look at other people's nodeJS repository, I see neatly organized code and folder structure by people who seem like they really know what they're doing. Meanwhile I look at mine, it's a mess. How messy you ask? the routes/controllers/services/all in one single index.js kind of mess. As convenient as it might be to not having bunch of tabs open, it's not the best practice. So I set on mission to perfectly organize my folder structure.
To do that, I went through a bunch of other people's repositories, read a bunch of articles and basically what I learned was there is no one-size-fits-all approach. However in my case, I did end up with a folder structure that I think will make my code somewhat maintainable.
App folder: ->client (consists of the client side VueJS) ->server --->controllers --->routes --->models ---services --->helpers --->server.js (app entry point) ->.env / . git (and other stuff)
Here I'm only focusing on the server side nodejs. The main components are :
- services: consists of methods that does the CRUD(Create Read Update Delete) dirty work
- controllers: takes user request (HTTP requests in our case) and tells the services what to do
- models: represents the database schema
- routes : were done using express to connect urls (user's get and post requests) to controllers
- helpers: ???
So this is how I'm going to organize my Nodejs folder structure for my project.
Thanks for reading and would appreciate any insights into this matter.
P.S. Please follow me on twitter, I'd really appreciate it. @Nipeshkc