• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Demonstrates the ability to mount multiple Express apps into a single Express host app

Express Sub-App Demo

An extreme example of separating what may have been a single Expres app into multiple applications with a host to bring them back together.

About This Demo

Express is one of the most flexible web hosting libraries I have used in my career. I love how simple it can be, and how it allows you to grow your system as needed.

One of the areas that has continued to bother me in my own code, is my lack of ability to cleanly separate different parts of my express app while having those parts hosted in the same root domain name.

Prior Attempts To Separate Code

Previously, I had separated what may have been a /admin route into a completely separate sub-domain, like http://admin.example.com.

With the realization that Express application instances can be mounted into other Express application instances, however, that changed.

Mounting Sub-Apps Into A Host

While I do see value in moving /admin out to a separate sub-domain, still, I also see a lot of value in separating /admin into it's own project folder and still mounting it as /admin in the main Express app.

This repository is a demonstration Express' ability to do just that - to take what would have been cluttered code from multiple route paths, separate them into their own application instance, and bring them back together in a single application host.

On Being An "extreme" Example App

I call this an "extreme example" because I have purposely taken the separation out to the edge of what I might consider useful. Taking this to an extreme allows us to see the bounds of where this might be useful.

It is still possible to take this separation of apps further, creating more sub-applications to split further responsibilities apart.

For example, you could split the "development" vs "production" error handlers into separate app instances, and only mount the one you need.

However, this might really jump the bounds of usefulness... depending on your circumstances, of course. :)

Running The Demo

Clone the repository, then

  • npm install from the root folder
  • npm start from the root folder
    • alternatively: run node host/bin/www

Project Structure

This demo project is split up into multiple Express application instances, each of which handles a specific portion of the over-all web application.

The primary application is:

  • host: The root express app and the actual web server into which the other apps are mounted

The sub-application instances include:

  • api: Mounted at /api, handles the JSON based API access for the app
  • web: Mounted at /, handles the core web pages for browser based usage
  • errors: Mounted in the root express app, handles root level 404 and route / middleware errors

You'll note in each of these projects, that various parts of the default Express app (as generated by the Express-Generator project) have been removed.

For example, the api project does not need to render any Jade views, so the view engine registration and views folders have been removed from this project. Similarly, none of the sub-applications need to have actual web server code from the bin/www file - only the host application needs this.

By separating the application into multiple sub-apps, code is easier to maintain as it contains less clutter from unrelated things.

Legal Junk

Copyright Β©2016 Muted Solutions, LLC. All Rights Reserved.

Distributed under MIT License.

More Repositories

1

backbone.modelbinding

awesome model binding for Backbone.js
JavaScript
700
star
2

backbone.memento

store and restore your model's state
JavaScript
367
star
3

mustbe

Authorization plumbing for NodeJS/ExpressJS/ConnectJS apps
JavaScript
320
star
4

Albacore

Dolphin-Safe Rake Tasks For .NET Systems
Ruby
240
star
5

jasmine.async

Make Jasmine's asynchronous testing suck less.
JavaScript
136
star
6

backbone.picky

selectable entities as mixins for Backbone.Model and Backbone.Collection
JavaScript
129
star
7

rabbus

A micro-service bus with built-in messaging patterns, for NodeJS and RabbitMQ
JavaScript
116
star
8

solid-javascript

SOLID JavaScript In A Wobbly World (Wide Web)
JavaScript
70
star
9

nanit

Node Application Initializers
JavaScript
56
star
10

migroose

MongoDB database / data-structure migrations, for MongooseJS models and schemas
JavaScript
55
star
11

appcontroller

An example Application Controller implementation for C# WinForms applications
C#
35
star
12

emberclonemail

A sample application written with EmberJS
Ruby
32
star
13

backbone.compute

Computed fields for Backbone.Model
JavaScript
31
star
14

presentations-and-training

Material used for presentations and training classes
C#
26
star
15

backbone.fwd

forward events from one backbone object, through another
JavaScript
20
star
16

bowie

An experiment in beautiful models with ES6 elegance
JavaScript
19
star
17

hands-on-backbone

The sample code to go along with the "Hands-on Backbone.js" screencast series from PragProg.com
JavaScript
18
star
18

iam

Simple authentication plumbing and middleware for Node/Express apps
JavaScript
15
star
19

bada55-node-dev

How to build your own #BADA55 NodeJS development environment
JavaScript
14
star
20

UnitOfWork

A C# UnitOfWork Implementation For NHibernate. Supports WinForms and ASP.NET.
C#
12
star
21

epa

simple environment configuration for nodejs apps, using json files
JavaScript
11
star
22

speccy

simple javascript specification pattern implementation for nodejs / browserify
JavaScript
9
star
23

appcontroller.cf

Application Controller example code for the .NET Compact Framework
C#
8
star
24

jquery-to-backbone-marionette

code demo for my "jQuery To Backbone + Marionette" talk
JavaScript
8
star
25

boebotjs

Make Your Bot GO! With JavaScript!
JavaScript
8
star
26

Security

A small, role based security module for .NET apps
C#
7
star
27

vimbacore

a playground to try out c# coding in vim and figure out what albacore's csc task needs
Ruby
7
star
28

docker4js

Docker for JavaScript Developers - 2 day, hands-on training course from Derick Bailey
JavaScript
5
star
29

migroose-cli

command line tooling for mongrate, the mongodb/mongoosejs migration framework
JavaScript
5
star
30

5-tips-to-improve-js-with-es6

presentation given at Crater Remote Conf, Feb 10th, 2016
JavaScript
5
star
31

backbone-sinatra-boilerplate

My boilerplate cruft for working with Backbone.js in a Sinatra-backed app
JavaScript
5
star
32

MyFirstMVCSeleniumTest

How To Get Started With Selenium Core And ASP.NET MVC
JavaScript
4
star
33

classyobjects

A class-y inheritance example for JavaScript
JavaScript
3
star
34

backboneplugins

website for backboneplugins.com
CSS
3
star
35

ninject.rhinomocks.cf

Automocking container for RhinoMocks, running on Compact Framework
C#
3
star
36

5-stages-of-developer-grief

Presented at SpaceCityJS 2015
3
star
37

vimfiles.osx

my osx .vim folder and .vimrc
Vim Script
3
star
38

5-stages-of-entrepreneurial-grief

presentation for PrarieDevCon 2015
3
star
39

ninject.rhinomocks

Automocking container for RhinoMocks
C#
3
star
40

growing-express-architecture

Growing Express.js Architecture - a talk given at JSRemoteConf on Jan 15, 2016.
3
star
41

node-oracledb-cpu-leak

app to demonstrate node-oracledb cpu leak / spike
JavaScript
2
star
42

gitup

Automate the git update dance
Shell
2
star
43

execubot.js

A sample WebTask.io project: Read and execute code from a gist, post it in slack channel.
JavaScript
2
star
44

backbone.presentation

My slide deck for a Backbone.js presentation
JavaScript
2
star
45

cheesewiz

Correctly package localized resource files in .NET Comptact Framework .cab deployment projects
C#
2
star
46

jsfuncalc

An exercise in creating a functional javascript calculator
Ruby
2
star
47

ocarina

Simplified API for Oracle, built on top of official orabledb library
JavaScript
2
star
48

apologypro

apology.pro: because you're an amateur
JavaScript
2
star
49

boxing

terrible dropbox api and express middleware
JavaScript
2
star
50

mutedsolutions

website for my company
CSS
2
star
51

alt-tekpub

An open rewrite of Tekpub using Node, MongoDB and other buzzwords
JavaScript
1
star
52

objects

1
star
53

vimfiles.windows

my vim files and _vimrc for windows
Vim Script
1
star
54

derickbailey.github.com

My Github Homepage!
1
star
55

rabbus-sequence

process messages in sequential order with Rabbus and RabbitMQ
JavaScript
1
star
56

puzzleblocks

a command line game inspired by the Nintaii game that I play on my Droid
Ruby
1
star
57

traffic-limiter

Limit the number of tasks being run, based on task key/type
JavaScript
1
star
58

express-depot

mount Express sub-apps and middleware from a directory listing
JavaScript
1
star
59

react-todo-example

a basic example of organizing code in a basic react/redux app
JavaScript
1
star
60

wacotechlunch

Waco Tech Lunch
1
star
61

dotfiles

my dotfiles
Vim Script
1
star
62

node-jasmine-async

Making Jasmine's async suck less (for Jasmine v1.3)
JavaScript
1
star