0

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.

2 Answers 2

3

The coffee-script module provides a "compile" method:

var cs = require('coffee-script');
var js = cs.compile('foo = -> "bar"');
Sign up to request clarification or add additional context in comments.

Comments

1

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'"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.