On Fri, Nov 11, 2011 at 1:45 AM, Anatoly Geyfman <[email protected]>wrote:
> @jake - thanks for the MVC overview. > > My question was specific to node.js - for, let's say, an express.js > application. are there best practices for layout of directory structure? > No. However I can recommend src/init/configure.js src/init/bootstrap.js configure configures your express server. It sets your production and dev configuration modes. It applies all your middleware to your express server bootstrap calls configure, opens database connections, loads all the routers, sets hot code reloading watching, sets any other bootstrapping mechanisms you need src/routers Router contains a bunch of routing folders, roughly 1-1 mapping with the domain objects. In each routing file you pass in the express server and they attach routes to whatever they please src/data src/domain src/public src/public/views src/public/js src/public/css src/server.js Server.js simply starts the server > recommended component patterns? > "component patterns" is too vague > what do you export from a class? > "class" is to vague. A prototype is a blueprint, use it when you want to create objects > where do you put custom middleware? > In the routers (route specific middleware) or in the configure (app specific middleware) > how about parameter processors? > I process req parameters in the constructor for my domain objects. It's part of the input validation > things like that. While I get the MVC nature of express, the fact that > there isn't much in terms of best practices in this area makes this a > question that needs some attention. > Again rather then "adept" best practices, people just write modular code. Split it up sensibly, keep it DRY. Stick to Single responsibility. If you follow generic good practices you don't need someone else to tell you "this is how thou shall architecture your code" > > Thanks, > > Anatoly > > > On Thu, Nov 10, 2011 at 6:06 PM, Jake Verbaten <[email protected]> wrote: > >> Generally applications have 4 parts to them >> >> - Routers. You take a reference to you router and register URI fragments >> to callbacks. These callbacks talk to your domain objects or data layer and >> then pipe them through your views >> - Domain objects. These represent the REST resources you have. Generally >> they have constructors from user input that do aggressive validation. They >> also talk to your data layer. >> - Data layer. Simple wrapper around your database, these methods talk >> directly to your database or any other data source you have >> - Views. Any Domain object -> HTML/JSON/XML/etc conversion system you >> want. >> >> [Image]( >> https://docs.google.com/drawings/d/1_uUvXjop0PazdhnVkiF3Do5UTCiN1I-Nt3oMylGwgyc/edit >> ) >> >> basically you have bidirectional communications. The router is a central >> middleman that asks every other module to do a task for it. It's a very >> simple modular architecture. You also deal with websockets by having the >> domain objects emitting change events and the domain objects can emit >> change events either manually or by listening on database push events. >> >> If you want to 1up it have every thing live in it's own hook (hook.io) >> and then use cross process communication between them. >> >> >> On Fri, Nov 11, 2011 at 12:39 AM, Anatoly Geyfman <[email protected]>wrote: >> >>> Codeigniter related items aside (which are irrelevant and >>> counter-productive), the question is a very good one, and not very much >>> addressed on the webs. How do you guys structure your node.js apps? >>> >>> Thanks, >>> Anatoly >>> >>> >>> On Thu, Nov 10, 2011 at 4:27 PM, Timothy J. Warren >>> <[email protected]>wrote: >>> >>>> Mediocre in what way? That it doesn't have arbitrarily forced paradigms >>>> of other frameworks? It's not like I put all of my logic into controllers. >>>> >>>> The point is flexibility and simplicity. I'll look into those libraries >>>> to see how they handle it. >>>> >>>> >>>> >>>> -- >>>> To view archived discussions from the original JSMentors Mailman list: >>>> http://www.mail-archive.com/[email protected]/ >>>> >>>> To search via a non-Google archive, visit here: >>>> http://www.mail-archive.com/[email protected]/ >>>> >>>> To unsubscribe from this group, send email to >>>> [email protected] >>>> >>> >>> -- >>> To view archived discussions from the original JSMentors Mailman list: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To search via a non-Google archive, visit here: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To unsubscribe from this group, send email to >>> [email protected] >>> >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected] >> > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
