I am using Express v3.0.0rc1 with Node v0.8.1 and I am trying to create a webserver that works off of a modular system for displaying routes and views.
Is there a way to display stylesheets and client-side javascript files from within the ./modules/foo/
directory instead of ./public
when display requests from within the foo module routes?
My approach would be to set up an additional static middleware layer. This has the limitation that the static files used by your modules must have different names since any name conflicts will result in only the resource from ./public
being served. According to this SO Setting up two different static directories in node.js Express framework, this may be the best you can do.
var express = require('express');
var http = require('http');
var app = express(); // Express 3+
var server = http.createServer(app);
app.configure(function(){
app.use(express.bodyParser()); // Parses incoming request date.
app.use(app.router); // Mount application routes
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/module/foo'));
});
app.get('/', function(req, res) {
res.send("Hello World!");
});
server.listen(3000, 'localhost');
});