javascriptnode.jsexpressvhostsnode.js-connect

Using connect vhost to serve multiple express.js apps


I want to use connect's vhost functionality to deploy several express.js apps to my dev vps. Here is my server.js file that is supposed to send requests to the appropriate place:

var express = require('express')
var quotes = require('quote-of-the-day/lib/app.js');    
var server = express();  
server.use(express.vhost('inspiringquoteoftheday.com',quotes));    
server.listen(80);

Running node server.js throws this error:

Error: Cannot find module 'quote-of-the-day/lib/app.js' 

Even though I can cd into app.js straight from the directory where server.js is located.

Here is the lib/app.js file in which I export my express app (I think)

// Generated by CoffeeScript 1.3.3
(function() {
  var app, express, pub;

  express = require('express');

  module.exports = app = express();

  pub = __dirname + '/public';

  app.use(express["static"](pub));

  app.use(express.errorHandler());

  app.use(app.router);

  app.set('views', __dirname + '/views');

  app.set('view engine', 'jade');

  app.get('/', function(req, res) {
    return res.render('home');
  });

}).call(this);

Solution

  • Assuming a directory structure that looks something like this:

    |-. quote-of-the-day
      |-- server.js <-- the file you list in your question
      |-. lib
        |-- app.js
    

    Then you should require your app.js with

    require('./lib/app');