NodeJS - how to export a module correctly

Given two modules a and b. I know that it is possible to expose a's functionality to another module using the module.exports. I probably do not use it correctly.

a.js

function A() { ... }
A.prototype.func = function() { ... }

function test() {
    new A().func();
}

test();
module.exports = {
    A : new A()
};

The test() is working correctly. But the following breaks:

b.js

var A = require("./a");
A.func(); //throws an exception

How do I export the whole A module with its functionality?

Update: executing console.log(A) over b (as a second line), does not reveal any of A's methods and variables.

Try this:

module.exports = new A();

You won't be able to instantiate a new A in b, but it seems like that's what you want.

Edit:

Or you could change b.js to:

var A = require('./a');
A.A.func();

But this is likely not what you want.

The idea is that whatever exports is will be what is returned from require. It's exactly the same reference.