What are my restrictions if I want to code node.js and use CoffeeScript? Can I do anything I'd be able to do in JS?
Yes, CoffeeScript simply compiles into pure JS, making it completely compatible with node.js. To run CoffeeScripts on node, you can either:
|
|||||||||||||||||||||
|
Not only can you run CoffeeScript files directly in Node with
you can also require them as if they were JavaScript files. For instance, if you have
from another CoffeeScript file in the same directory. (In order to do this from a JavaScript file, you'll have to add One caveat: In stack traces, the line numbers you'll see refer to the compiled JavaScript, even when you're running CoffeeScript directly (so you don't have access to the JavaScript). A lot of folks are trying to fix this, but it's a big challenge. |
|||||||||||||||||
|
Yes, here's a different & simpler answer. You need to do 2 steps.
This registers coffeescript compiler to your app and you can start treating coffee files and js files equally now (meaning that you can require coffee files too !). This method will require you to write just the one file (app.js) in vanilla javascript. But the advantage is that your deploy environment need not have coffeescript as an initial globally installed dependency to run your app. In this case, you would just have to copy over your code, and |
|||||
|
Video Tutorials I've seen a great tutorial series by Pedro Teixeira. He's been building an entire series on node tutorials. He includes reference to nodemon for auto detection and compilation and reloading of edited .coffee files. |
|||||||||||||||||
|
Coffeescript + ExpressJS + Couchdb + Redis + Auth: |
|||||
|
You can use Jitter, a Simple continuous compilation for CoffeeScript.
Let's say you have a bunch of *.coffee files in the coffee directory, and want to compile them to the js directory. Then run:
Jitter runs in the background until you terminate it (Ctrl+C), watching for new changes. |
|||
|
Try this
Then do:
CoffeeScript has pretty solid integration with node. Once the 'coffee-script' module is loaded, either by |
|||
|
If you want to automatically compile all your coffeescript files (in one directory including subdir) every time they change into javascript, just use this command:
|
|||||
|