How can I share modules between the client and server using node.js if my module depends on another?

Here's my Node.js situation:

I'm trying to share code between my Node.js server and the browser for a game. Basically, I want to share the game logic.

Lets say my game has a Table, and that Table can have Players. I want each of these to be modules that can be used by both the client and server.

I know I can do something like this:

(function(exports){

   exports.test = function(){
        return 'hello world'
    };

})(typeof exports === 'undefined'? this['Table']={}: exports);

And I can get something like this working with my Table. However, what if I need to use Players inside this Table module? Something like:

(function(exports){

   exports.test = function(){
        var Player = require('./Player');
        var p1 = new Player();
    };

})(typeof exports === 'undefined'? this['Table']={}: exports);

While this would work in Node, it obviously wont in on the browser, since require is not defined. And without require, it would work on the browser, but not Node.

TL;DR: I need to "include" code from one module in another module, which can be shared by both the browser (client) and server.

Thanks

You could use require.js to load modules in both node and the browser.

See documentation on the require.js page