Reputation: 9491
Is it possible to compile a string of coffeescript with the npm module, I have been looking everywhere and cannot seem to find any good answers.
Upvotes: 0
Views: 147
Reputation: 5727
If you're talking about the coffee
command line utility, then yes you can (although it isn't too pretty):
echo "alert 'Hello World'" | coffee -sc
The code above compiles the CoffeeScript in the echo and outputs to STDOUT. If you want the compiled output in a file, you can do this:
echo "alert 'Hello World'" | coffee -sc > path/to/file.js
There's some good documentation on the command-line utility here: http://coffeescript.org/#usage
If you mean compiling a string within CoffeeScript code, the coffee-script
module provides a compile function:
coffee = require 'coffee-script'
js = coffee.compile "alert 'Hello World'"
Upvotes: 1
Reputation: 26730
The coffee-script module provides a "compile" method:
var cs = require('coffee-script');
var js = cs.compile('foo = -> "bar"');
Upvotes: 3