Reddit reviews Node.js Design Patterns: Master a series of patterns and techniques to create modular, scalable, and efficient applications
We found 2 Reddit comments about Node.js Design Patterns: Master a series of patterns and techniques to create modular, scalable, and efficient applications. Here are the top ones, ranked by their Reddit score.
I'd recommend node design patterns (http://www.amazon.com/Node-js-Design-Patterns-Mario-Casciaro/dp/1783287314) for reading on the subject.
In general I make everything a module - from the router to the endpoint logic to the database integration. Not a full on NPM module, unless I'm doing microservices, but each module will have its own tests and generally not be coupled to anything else except its dependencies - it should stand on its own within reason, because then it'll be more testable and maintainable. The module system in node works very nicely for this, since you can just export the "public" functions and hide the private ones much like classes in a traditional OO language.
Also important is if you're using large libraries to make wrapper modules. Even if I don't ever plan to move off of mongoDB for my database module as an example example, I still expose my own interfaces rather than the direct library ones so if I ever need to swap it out its a simple method of updating that module, not any of the calls to it. Refactoring module interfaces often is what gets you in more trouble, so that lets me keep my changes in one place.
The rest you can get through guides and reading... error handling and asynchronous flow control (parallel, series, combinations) are the biggest hurdles in node. I use just callbacks and async because I feel its a little easier to reason about, but promises and async/await work as well. Whatever you use stick with it. Always handle errors - an uncaught exception will take down your server. Expect it to happen even if your code is rock solid, and have a plan for spinning down gracefully (uncaught exception handlers - read recent articles there's a lot of bad older ones out there) and restarting the process (forever, pm2, other process managers).
Javascript can be a really tricky language to truly understand. It's known as the "most misunderstood language" for a reason, and that's because for the most part, developers have been fine with just knowing the basics and coming up with solutions using limited knowledge. Your difficulty with getting the ball rolling with Node is almost definitely due to a lacking understanding of the Prototype-based nature of Javascript, and all the unique characteristics of a language as a result of Prototypes. I also started Node with a Java (OOP) background, and ran into difficulties right away. Here's how I approached Javascript (and Node) and saw quick results (don't get me wrong, there's a lot of work involved, but you'll notice how much more sense the language makes to you rather quickly).
This method turned me from your average Javascript kiddie to a solid JS wiz. Might work for you too.