0

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);
aynber
  • 22,380
  • 8
  • 50
  • 63
Msencenb
  • 5,675
  • 11
  • 52
  • 84

2 Answers2

0

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');
Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • My directory structure was a bit different... but I forgot that nice little ./ due to not being on ubuntu for a bit. Thank you – Msencenb Sep 08 '12 at 03:01
0

Might be helpful to use the __dirname global variable here. it provides 'the name of the directory that the currently executing script resides in.' thus you could do:

var otherApp = require(__dirname + 'quote-of-the-day/lib/app.js')

http://nodejs.org/docs/latest/api/globals.html

bhurlow
  • 2,019
  • 2
  • 16
  • 14