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. As convenient as it might be to not having keeping everything in a single file, 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
So this is how you can organize you Nodejs folder structure for your project.
Thanks for reading and would would love to hear any insights into this matter.
Follow me on Twitter: @Nipeshkc*
Visit my blog: blog.arpankc.com