Mario Casciaro wrote:Hi Albareto,
in my opinion, one of the features that make Node.js enjoyable to use is that dependencies are explicit. In Java is very common to use a dependency injection container, which adds a level of indirection, which somewhat complicates the readability of the code. In Node.js, if you want to import a singleton, you can just export an instance from a module (e.g. module.export = new MyClass()) and import the singleton with a simple call to require() or import. It's that simple.
To me, a "clean" architecture in Node.js, means creating modules that do only one thing and well (cohesion) and that expose a minimal interface (information hiding). Organizing those modules in a coherent directory structure is also important.
To be honest, in my early days of Node.js, I too struggled to apply the knowledge I had acquired from using Java and other strongly typed languages. In fact, one of my early Node.js projects was a dependency injection container. With time I learned to let go of my old mindset and accepted the fact that in Node.js certain things are just basic simple and in my opinion, that's amazing.
PS: This is such a common question that in the book we have dedicated section called "Wiring modules" where we talk exactly about that.
Zach Rode wrote:Not a JS person, but I'm pretty sure nodeJS is only executed server-side.