I am trying to setup an interface, where I can write one js file that can be used on the server (nodejs) and on the client (javascript).
An example file would be a Vector object, that I would like to use on both the client and the server, as I am creating a multiplayer game.
In node.js, I know that you can use the following syntax to require source files...
var Vector = require('./vector');
Then you can access its module.exports by typing in Vector.
The problem here is that for the server I need an extra bit of code at the end of the file...
module.exports = Vector;
... which is not necessary on the client.
Is it possible to maybe require source code, something like the following?
var data = (...) // get data from vector.js file
var Vector = require_code(data + 'module.exports = Vector');
If not, there might be another way of doing what I am trying to accomplish.
That might sound a little confusing, but help is greatly appreciated!
Thanks in advance,
David.