Q:

Access variable in main node file from an imported file

//in app.js
var x = require("x.js");
var instanceX = new x();
require("./Weather")();

//in Weather.js
instanceX.getName();

In this case instanceX wouldn't exist when referenced from Weather.js. How do I make instanceX accessible in Weather.js?

A:

There are a number of different ways to approach this in module design.  One simple way is to just pass the variable to the weather.js constructor:
//in app.js
var x = require("x.js");
var instanceX = new x();
require("./Weather")(instanceX);

//in Weather.js
var instanceX;
module.exports = function(ix) {
    instanceX = ix;
}

// then elsewhere in the module
instanceX.getName();

I refer to this as the "push" model because you're pushing things to the module that you want to share with it.

