So let's say I have a string of coffeescript code, in a javascript file on nodejs. How could I convert this string into javascript, without using the terminal? I have tried coffeescript-compiler, but it gave me an error about a closed socket. I have coffeescript installed globally and coffee-script compiler installed locally.
Edit: Here is the code:
var Compiler = require('coffeescript-compiler');
var cc = new Compiler();
cc.compile('a = 5', function (status, output) {
if (status === 0) {
// JavaScript available as a string in the `output` variable
}
});
And here is the error it throws:
events.js:72
throw er; //unhandled 'error' event
Error: This socket is closed.
at Socket._write (net.js:637:19)
at doWrite (_stream_writable.js:225:10)
at writeOrBuffer (_stream_writable.js:215:5)
at Socket.Writable.write (_stream_writable.js:182:11)
at Socket.write (net.js:615:40)
at doCompile (D:\TSA\App\node_modules\coffeescript-compiler\Compiler.js:33:15)
at Compiler.compile (D:\TSA\App\node_modules\coffeescript-compiler\Compiler.js:46:3)
at Object.<anonymous> (D:\TSA\App\coffeescript.js:4:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
coffeescript-compiler? It is definitely the thing to use.