1

I'm using coffeescript for my current node.js project, starting the project with the following command (inside my project folder)

coffee app.coffee

Which starts the node application. I am, however, at a loss as to how node.js can interact with the coffeescript - is it compiled to a temporary folder?

3
  • 3
    well, a source file is just some text put into a file on the disk. you can anytime fire up the node REPL and execute the source (text) you enter on the command line without producing a file.—just a tip: i've found that compiling and running my code with, say coffee -o lib -c src && node lib/mymodule.js has greatly improved the overall interoperativity of my code, as it does not depend anymore on (some particular version of) CoffeeScript to be present on another machine when installed there. Commented Aug 6, 2014 at 13:00
  • Thansk for the reply, @flow. I think what I still don't get is how node is able to interpret my coffeescript code (as opposed to javascript). In my head it needs to be compiled somewhere before node can execute it, but I guess this might be handled by node internally? Thanks for the tip btw! :-) Commented Aug 6, 2014 at 13:21
  • indeed, the coffee command will read the file contents, translate them into JavaScript, and then execute that code using (something similar to) eval. node itself never gets to see the CS source, much less is node itself obliged to know anything about CS semantics. this transparent 'compilation on the fly' has been added for convenience; as soon as projects get bigger, i think you're better off with making that step explicit. immediate bonus: runtime errors will point to JS source lines, and it's then handy to have the relevant files. Commented Aug 6, 2014 at 13:54

1 Answer 1

1

Do this:

cat `which coffee`

And you'll see that coffee is actually a node script, which compiles your .coffee file and then runs it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - I think what threw me was the fact that the node process was being invoked simply by running the coffeescript compiler (i.e. without the node keyword). It seemed rather odd to me that a single javascript file (after being compiled through coffeescript) would recognize itself as a node project file with no prompt from the user.

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.