Monday 25 April 2016

Structuring an Express app to be scalable

I'm an instructor at a programming bootcamp, and until now I've been using Express exclusively for creating small RESTful API servers. I want to spend more time learning/understanding Express in terms of server-side rendering so I can teach that as well. I started in the world of Django, which is very opinionated and did a lot of the bootstrap work for you, so I'm trying to understand the best way to structure an Express app in preparation for it to become large, perhaps even very large.In Django, you modularize your project by splitting it into apps and adding the apps to the setting's installed_apps array. Each app has its own models, views, and templates directories. This structure makes sense to me, where each "app" is an individual, standalone (or nearly standalone) component of the whole project, like having an "authentication" app whose only job is to do authentication, an "emailer" app whose only job is to send/route emails, etc.How would you accomplish this same structure with Express? So far I've only ever run a single express server app on a port and mounted my middleware, routes, Mongoose models, etc. on it, but never other express apps.I'm wondering if there's a solid resource I can refer to to learn that kind of structure. The only hint I'm finding so far in the docs is something about "mounting" other apps on top of a main express app, but if I could get some examples (even if it's pseudo-code), that would help me tons so I can learn it well enough to teach it.For example, if I wanted to organize all the views/templates, mongoose schemas/models, and routes for an "authentication" app to be separate from the main app's views/templates, schemas/models, and routes, how would I go about doing that?Thanks in advance!

Submitted April 25, 2016 at 08:39PM by bobziroll

No comments:

Post a Comment