It\'s pretty easy to do this with coffee-script.
var coffee = require(\'coffee-script\'); coffee.compile(\"a = 1\"); //=> \'(function() {\\n var a;\\n\\n a
better-require could help you achieve this.
It lets you require() typescript files - no pre-compilation needed - and a bunch of other file formats (coffeescript, clojurescript, yaml, xml, etc.)
require('better-require')(); var myModule = require('./mymodule.ts');
Disclosure: I wrote better-require.