1

I'm just curious how people structures their Node.js app?

Usually I create models/ views/ controllers/ and that's simple as that. But I'm kinda new to the Node.js scene and I'm trying to learn as much as I can about how the community works.

Any answer is welcome, thanks!

Tommy B.
  • 3,591
  • 14
  • 61
  • 105
  • 2
    Structuring applications is personal preference and developer specific, just do something your comfortable with. (and it has to be logical!) – Raynos Mar 07 '12 at 20:12
  • I was just curious, I think my current setup is alright IMO but I'm always looking for something better hehe :P – Tommy B. Mar 07 '12 at 20:18

1 Answers1

4

For what it's worth, my actual setup is this, until I come up (or find) something clearly better:

lib
  db
      index.js
      model.js
      ...
  handler
      index.js
      whateverMakesSenseForMyParticularWebSite.js
      ...
  router
      index.js
      model1RestRoutes.js
      model2RestRoutes.js
      iuRoutes.js
      ...
  config.js (or a folder with multiple files if it makes sense)
  server.js (main)
public
  css
  img
  js
test
  ...
views
  ...

So yes, models, views, but I do separate routes and actual handlers' implementation. Decoupling, dependency injection all the way. Way more testable/mockable.

mna
  • 22,989
  • 6
  • 46
  • 49