Tommy B.
Tommy B.

Reputation: 3639

How should I structure my node/express/mongodb app?

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!

Upvotes: 1

Views: 1094

Answers (1)

mna
mna

Reputation: 23963

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.

Upvotes: 4

Related Questions