I am making a node js webapp and i tried organizing it with separating my code in different modules, so i was wondering whether my modules are too small/big and are they badly organized. How much code should a module contain? Currently my code is organized a model per rout.
I’m not sure there’s some single, definitive answer for this. Different programmers and teams will have their own particular style. If I had to suggest one rule, it would be to err on the side of more, smaller modules rather than huge chunks of code. I rolled all of my backend API projects into one repo, so I had to organize the files in a way that was flexible and maintainable. I didn’t entirely succeed, but I learned a lot.
app.js file is quite busy as it takes care of setting up middleware, server settings, and routing. Each route has its own route file. Each route file takes care of the more granular routing required for each module, but the logic is all handled by modules written in
/helpers, which get imported in the route files. I like that I separated my logic handling into modules. I don’t like that my
app.js file does so much. I could clean it up a lot by creating a single router module and import that into
Check out my project if you’d like to see how I organized things (stay out of the code in
/helpers if you haven’t completed the projects yet).
If there is no mainstream way i`l stick to what fits me. thank you for informing me. Good job PortableStick for making readable code and good job me for being able to understand it.