Skip to content

Instantly share code, notes, and snippets.

@wholroyd
Created June 19, 2015 18:57
Show Gist options
  • Save wholroyd/123086c2fe260240455a to your computer and use it in GitHub Desktop.
Save wholroyd/123086c2fe260240455a to your computer and use it in GitHub Desktop.
Nested Express apps. How it should be.
// ### The Root application
// ./index.js <- lives here
// ./views/index.hbs <- the view
// ./catsApp <- child app
var express = require('express');
var app = express();
var exphbs = require('express-handlebars');
app.engine('hbs', exphbs({defaultLayout: 'single', extname: '.hbs'}));
app.set('view engine', 'hbs');
app.get('/', function(req, res) {
res.render('index');
})
// This should be it's own instance, or have it's own locality of certain configuration options
// It should be able to have it's own view engine and be able to find views relative to it's root directory
app.use('/cats', require('catsApp'));
app.listen(3000);
// ### The Child Application
// ./catsApp/index.js <- lives here
// ./catsApp/views/index.jade <-- the view
var express = require('express');
var catsApp = express();
catsApp.set('view engine', 'jade');
catsApp.get('/', function(req, res) {
res.render('index');
})
modules.export = catsApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment