I am performing messaging via websockets between a HTML5 client and server running on node.js. Naturally I chose JSON as the message format and as such created common javascript
Take a look at nodeJS modules.
Would be in comm.js:
module.exports = function(/* any dependency? */){ // things // you can return some object }
In the files you need comm.js
require('./common/js/comm.js')(); // or you can assign it to a variable if it returned something
Hope that helps!