views:

38

answers:

1

I have 3 node files:

// run.js

require('./configurations/modules');
require('./configurations/application');

// modules.js

var express = module.exports.express = require('express');
var app = module.exports.app = express.createServer();

// app.js

app.configure(...)

Run.js requires both files, modules.js which require a module and creates a variable, and app.js which should use that variable. But I get an error on app.js cause app isn't defined.

Is there a way to make this possible?

A: 

It looks like you're defining the variable in modules.js, but trying to reference it in app.js. You'll need to have another require in app.js:

// app.js
var application = require('./path/to/modules'),
    app = application.app;

app.configure(...);
jmar777