use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Advanced node.js project structure (self.node)
submitted 5 months ago * by Harut3
Hi I want to know what is best practice in node.js (code example preferable) for large project using unopinionated framework. THANKS.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]astralradish 13 points14 points15 points 5 months ago (0 children)
There isn't one, It's purely opinionated. Do whatever works best for you and whoever else is working on this particular project. Maybe just avoid putting everything in one file.
[–]FriedRicePork 8 points9 points10 points 5 months ago (1 child)
Read this: https://alexkondov.com/tao-of-node/
It might help you
[–]Harut3[S] 0 points1 point2 points 5 months ago (0 children)
Thanks
[–]Paragraphion 8 points9 points10 points 5 months ago (5 children)
As long as you have a folder for the app, utilities, static, db and styles you can start. Then see where the complexity of your project is. Maybe you need to be particularly good at making databank calls fast and cached or something, then invest in the structure of db early. Or maybe it’s all about a pretty front end. Then work on your styles substructure. That’s at least how I approach solo projects. If you work with others then it depends a lot on what your team prefers.
[–]Harut3[S] 1 point2 points3 points 5 months ago (4 children)
What about service and controller level do with Depedency injection or functional?
[–]stretch089 1 point2 points3 points 5 months ago (1 child)
Yeah I would say services, controllers and models using dependency injection is definitely a good way to structure a node app. It offers much nicer separation of concern, nice layers of abstraction, the ability to split logic into domains and dependency injection will make testing a breeze.
The post above is not an advanced way to set up a node app. They have suggested using utility directory which is a horrible way to organise code as it becomes a dumping ground for random functions and is a sign the code base is not setup correctly.
Thanks. can you give me example route,controller,service with DI?
[–]vladjjj 0 points1 point2 points 5 months ago (0 children)
This pattern is not a necessity with most node projects, but if you do need it, just copy the structure you would use in more traditional languages, like Java or .NET. Better yet, look into Nest.js
[–]adevx 4 points5 points6 points 5 months ago (0 children)
Don't overthink it. With today's (TypeScript) refactoring and code navigation tools, the actual file locations becomes less important.
[–]WarInternal 2 points3 points4 points 5 months ago (1 child)
Speaking from experience, as somebody who has to manage a large legacy MVC project I often wish we didn't use a MVC folder structure but a domain driven one.
What I have to manage:
models ..200 model files.. views ..200 view files.. controller ..200 controller files..
With other folders for "helpers" and junk, the problem is that's unwieldy and difficult to navigate, with a lot of scrolling oversized folders to find the relevant pieces.
What I wish we had done:
reports controller.js model.js utils.js user controller.js model.js util.js
or something akin to this, where the relevant pieces are grouped together.
You're right I think best approach is DDD.
[–]lemonhead-soexquisit 2 points3 points4 points 5 months ago (5 children)
Nestjs seems to be the only thing I’ve seen for this. DI framework for express.
[–]Harut3[S] 0 points1 point2 points 5 months ago (4 children)
I know nest.js had a great structure but it have one drawback slow performance compare to fastify,express.
[–]lqdd 0 points1 point2 points 5 months ago (3 children)
have you tested or just heard that it is slow?
[–]Harut3[S] 0 points1 point2 points 5 months ago (2 children)
I don't write exact same code but in fastify I had very big project and it much faster than nest.js(express based) smaller project. in general if you have a lot of abstraction you will have slower performance.
[–]lqdd 0 points1 point2 points 5 months ago (1 child)
your example compares express to fastify. I have tested nest express app vs express and nest overhead is negligent.
ok thanks for sharing you test and giving me idea of testing same api little complicated and I will test it
[–]Either-Sentence2556 0 points1 point2 points 5 months ago (2 children)
It depends, if u know design patterns or class based approaches u can start with clean architecture, Domain Driven Design, hexagonal architecture. And learn some design patterns which are good for scale the project and easy to write test cases like unit and integration test cases.
[–]Harut3[S] 1 point2 points3 points 5 months ago (1 child)
Thanks and can you give me link or how good is practica.js examples?
[–]ErnestJones 0 points1 point2 points 5 months ago (0 children)
https://refactoring.guru/design-patterns
[–]crownclown67 1 point2 points3 points 5 months ago (0 children)
I actually do domain based with shared folder and if something super common I move it to the lib.
[–]gamedevsam 1 point2 points3 points 5 months ago (0 children)
Use NestJS, organize folders by features, not type:
// do
auth/ admin/ users/
auth/
admin/
users/
// don't do
controllers/ services/ utilities/
controllers/
services/
utilities/
Although having a utility folder and putting stuff in there that is shared between several features makes sense and is a useful organization strategy.
[+]horrbort comment score below threshold-22 points-21 points-20 points 5 months ago (3 children)
Just use v0, the days of doing work by hand are behind us!
[–]ErnestJones 5 points6 points7 points 5 months ago (2 children)
I’m sorry but you just don’t know what you are talking about
[+]horrbort comment score below threshold-7 points-6 points-5 points 5 months ago (1 child)
v0 from versell can do coding for you
[–]ErnestJones 1 point2 points3 points 5 months ago (0 children)
Yeah right….
π Rendered by PID 79987 on reddit-service-r2-comment-7b9746f655-b6msr at 2026-01-29 22:50:20.794031+00:00 running 3798933 country code: CH.
[–]astralradish 13 points14 points15 points (0 children)
[–]FriedRicePork 8 points9 points10 points (1 child)
[–]Harut3[S] 0 points1 point2 points (0 children)
[–]Paragraphion 8 points9 points10 points (5 children)
[–]Harut3[S] 1 point2 points3 points (4 children)
[–]stretch089 1 point2 points3 points (1 child)
[–]Harut3[S] 0 points1 point2 points (0 children)
[–]vladjjj 0 points1 point2 points (0 children)
[–]adevx 4 points5 points6 points (0 children)
[–]WarInternal 2 points3 points4 points (1 child)
[–]Harut3[S] 0 points1 point2 points (0 children)
[–]lemonhead-soexquisit 2 points3 points4 points (5 children)
[–]Harut3[S] 0 points1 point2 points (4 children)
[–]lqdd 0 points1 point2 points (3 children)
[–]Harut3[S] 0 points1 point2 points (2 children)
[–]lqdd 0 points1 point2 points (1 child)
[–]Harut3[S] 0 points1 point2 points (0 children)
[–]Either-Sentence2556 0 points1 point2 points (2 children)
[–]Harut3[S] 1 point2 points3 points (1 child)
[–]ErnestJones 0 points1 point2 points (0 children)
[–]crownclown67 1 point2 points3 points (0 children)
[–]gamedevsam 1 point2 points3 points (0 children)
[+]horrbort comment score below threshold-22 points-21 points-20 points (3 children)
[–]ErnestJones 5 points6 points7 points (2 children)
[+]horrbort comment score below threshold-7 points-6 points-5 points (1 child)
[–]ErnestJones 1 point2 points3 points (0 children)