How can I configure multiple sub domains in Express.js or Connect.js

Or alternatively you could use vhost.

Then, create several sites in their own directory and export the express app, eg. /path/to/m/index.js:

var app = express()
/* whatever configuration code */
exports.app = app
// There is no need for .listen()

And then handle all requests with the following app:

var vhost = require('vhost');

express()
.use(vhost('m.mysite.com', require('/path/to/m').app))
.use(vhost('sync.mysite.com', require('/path/to/sync').app))
.listen(80)

Note that /path/to/m and /path/to/sync can be absolute paths (as written above) or relative paths.

Leave a Comment