115

How can I try CoffeeScript on Windows?

The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation

EDIT:

Since I asked this a while ago, many new answers have appeared. The number ( and quality ) of options for Windows users has been increased a lot. I "accepted" an answer a long time ago, then changed to other ( better ) answers as they came up, but I have now decided to not accept any answer, and let the community ( votes ) show which answers are best. Thanks to everyone for the input.

Nick Perkins
  • 8,034
  • 7
  • 40
  • 40
  • 1
    may be this will help http://stackoverflow.com/questions/2879401/how-can-i-compile-coffeescript-from-net – Arseny Jul 04 '10 at 17:50
  • Don't overlook Julian Birch's November 2011 answer re [a new Windows version.](http://www.colourcoding.net/blog/archive/2011/09/20/using-coffeescript-on-windows.aspx) – DOK Dec 10 '11 at 18:09
  • 1
    @Nick you should mark the answer from colonel panic as correct. It might take a while to bubble to the top on it's own, and it is the correct answer. – Billy Moon Jan 24 '14 at 15:10

13 Answers13

48

UPDATE: See my other answer to this question, How can I compile CoffeeScript from .NET? for a far more accurate and up-to-date list of the current options.

CoffeeScript-Compiler-for-Windows works well.

Community
  • 1
  • 1
liammclennan
  • 5,295
  • 3
  • 34
  • 30
35

Maybe it was more complicated when this question was posted. But as of 2012, CoffeeScript is as easy to use on any platform. The instructions are the same for Windows, Mac, or Linux

  1. Install Nodejs from http://nodejs.org/
  2. Install CoffeeScript globally with the node package manager npm install -g coffeescript or locally npm install --save-dev coffeescript
  3. Write a script in your favourite text editor. Save it, say as hello.coffee
  4. Run your script coffee hello.coffee or compile it coffee -c hello.coffee (to hello.js)
realplay
  • 2,078
  • 20
  • 32
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
20

Node.js runs on Cygwin these days, so that's probably your best bet with getting CoffeeScript running on Windows. I'd try that first.

If you have a different preferred JavaScript runtime, you can probably use the prebuilt-compiler (extras/coffee-script.js). For example, if you include that script on a webpage, you can call

CoffeeScript.compile(code);

... to get back the compiled JavaScript string.

UPDATE 2012-04-12: Cygwin is no longer needed to run Node on Windows. Microsoft worked with Joyent through 2H 2011 to improve node's support for Windows IOCP async IO. Node 0.6 was the first release of node to natively support Windows.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
jashkenas
  • 3,377
  • 24
  • 16
  • 1
    I don't think I need node.js ( see my edit )....but your "compile" suggestion is interesting! How exactly would that work? I would serve up both my coffeescript, and the compiler, and the browser would compile it down to regular javascript, and then run it? That would be cool! But how do you make that happen? Are there examples of how to do this? Would I be able to see the generated javascript?...and Debug it with FireBug? – Nick Perkins Jul 06 '10 at 15:13
  • 1
    Node.js is recommended. You can compile inline CoffeeScript in the browser, by including the compiler, and writing your code in a "text/coffeescript" tag. It's all eval'd that way, so you can't see the generated JS or debug it with Firebug... which is a long-winded way of explaining by pre-compiling it with Node.js is the best way to develop. For the details, see: http://jashkenas.github.com/coffee-script/#scripts – jashkenas Jul 08 '10 at 18:23
  • 5
    So I am going to need Cygwin to actually develop in CoffeeScript? That's ok, but I wish it was easier for a Windows user to get started. CoffeeScript looks really cool, I would switch all my javascript programming over to coffeescript if there was an eclipse plug-in that compiled on-the-fly like the excellent "Try CoffeeScript" interactive compiler/interpreter on the CoffeeScript website. That would be wicked! – Nick Perkins Jul 12 '10 at 01:59
  • The npm (node package manager) is also a convenient way to install and keep the package updated. – jerseyboy Feb 13 '12 at 20:32
17

You can run the CoffeeScript compiler under good old Window Script Host (cscript.exe), a standard component on Windows since Windows 98. Admittedly I tried this a while back and it didn't work, but I tried again recently and now all the standard CoffeeScript tests compile just fine.

A bit of plumbing code using a *.wsf file and coffee-script.js is all you need. My code is on GitHub: https://github.com/duncansmart/coffeescript-windows

I blogged about it here: http://blog.dotsmart.net/2011/06/20/the-simplest-way-to-compile-coffeescript-on-windows/

Duncan Smart
  • 31,172
  • 10
  • 68
  • 70
10

You can use jcoffeescript as a command-line solution.

It uses a Java-based javascript engine (Rhino) and wraps up the task of compiling coffee-script.js from the CoffeeScript project. This allows it to run the CoffeeScript compiler as a Java program.

The command to use (on Windows/Linux) looks like this:

java -jar jcoffeescript-1.0.jar < foo.coffee > foo.js

You will need to download & build the Java source code (use IntelliJ Community Edition to avoid downloading Ant) or a pre-built download for CoffeeScript v1.0.

I now use jcoffeescript in place of the Ruby solution (another answer here), because this allows me to keep up with the latest CoffeeScript version.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
PandaWood
  • 8,086
  • 9
  • 49
  • 54
  • Alternative command-line: java -jar jcoffeescript-0.9.2.jar < foo.coffee > foo.js – Duncan Smart Dec 08 '10 at 15:38
  • It does not used the same engine as Firefox. It uses Rhino which was developed by the Mozilla foundation but is completely unrelated to Fixefox. – mikerobi Dec 27 '10 at 19:08
8

You can use a command-line version of CoffeeScript by installing Ruby on Windows and then installing the CoffeeScript Gem.

After that, the command-line is available, for example, 'coffee bla.coffee' - to compile your CoffeeScript code down to JavaScript code.

The only disadvantage doing it this way (not using Node.js) is that the Ruby version of CoffeeScript is restricted to version 0.3.2 - the last version written in Ruby before it was moved over to Node.js.

*However, I still use the Ruby version of CoffeeScript in my current employment and my personal web page and I don't see much of a problem as this version of CoffeeScript is quite mature and most of the features listed on the CoffeeScript website can be used.

*striked out this last statement which was correct at the time but is becoming more incorrect every few days; CoffeeScript has now advanced a long way since 0.3.2 and is past 1.1

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
PandaWood
  • 8,086
  • 9
  • 49
  • 54
  • The gem is now in sync with CoffeeSscript (see the readme: https://github.com/josh/ruby-coffee-script#readme) however as a result it is only acting as a bridge/interface to the actual compiler so you still need node.js, etc. Also, the gem doesn't seem to be written with Windows in mind since it uses the "which" command to determine the javascript engine available and this command isn't available (by default) on Windows. – atomicules Jan 10 '11 at 14:17
  • 4
    That is not worth a votedown, the coffeescript gem worked on Windows and I used it for quite a while. Your comments are interesting but do not nullify the answer. Please don't vote down answers just because they have gone out of date since they were written – PandaWood Jan 10 '11 at 20:23
  • 1
    @PandaWood I was just using my votes to reflect the merit of the answers as I see them. I.e. the best solutions to the question are jcoffeescript (answered by you) and the Node.js binaries (answered by Mikhail Nasyrov). – atomicules Jan 11 '11 at 13:51
  • 2
    Just as a note, i5m is correct; downvotes are used to reflect the merit of an answer, and are not punitive. That is the whole idea behind higher-voted answers floating to the top. – Domenic Feb 23 '11 at 06:02
  • Note that the CoffeeScript Gem is being included with Rails 3.1, which speaks to its stability and support for all platforms, including Windows. – Trevor Burnham Apr 13 '11 at 17:54
  • @i5m so, a year later now, would you downvote yourself for your now-outdated answer? – DOK Dec 10 '11 at 18:12
  • @DOK Hi, I don't have a answer on this question so I can't downvote myself, but otherwise, yeah for sure. As per what Nick Perkin's has amended to his question: I think it's great that Stackoverflow isn't a static site and that the community can up/down vote answers to reflect the best solution at this moment in time. :-) – atomicules Dec 10 '11 at 19:31
6

There're already bunch of answers here, but let me add mine. I wrote a .NET library for compiling CoffeeScript on Windows.

As jashkenas suggested, I've used the pre-compiled extras/coffee-script.js file.
Together with the Jurassic JavaScript compiler I've wrapped it all up in a single library: CoffeeSharp

The library also ships with a commandline tool and a HttpHandler for ASP.NET web development.

Tom Lokhorst
  • 13,658
  • 5
  • 55
  • 71
3

I've used this one: https://bitbucket.org/maly/coffeescript-win/zealots looks working well, althouth you need to manually need to update coffee.script from 0.95 to 1.0.1.

D_Guidi
  • 698
  • 1
  • 5
  • 10
3

Since node.js is now ported to Windows, this is actually pretty easy:

http://www.colourcoding.net/blog/archive/2011/09/20/using-coffeescript-on-windows.aspx

Julian Birch
  • 2,605
  • 1
  • 21
  • 36
  • I like the answer, but will note that the process involves a git clone, so now you need to install GIT too even if you're not using it otherwise. – jerseyboy Feb 13 '12 at 21:09
2

If you want to use CoffeeScript in an ASP.NET application then you can use this HTTP handler to serve compiled CoffeeScript code.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
liammclennan
  • 5,295
  • 3
  • 34
  • 30
  • As is mentioned in the comments on this HttpHandler, by Liam, it's quite a hack, but a pretty ingenious one! It should hold us over until someone ports NodeJS to windows – PandaWood Aug 20 '10 at 00:34
1

I haven't tried this myself yet, but it seems to be an answer. (I've downloaded and installed but not used it yet.)

There's an add-in for Visual Studio 2010 that adds CoffeeScript editing to VS (among other things).

It's called Web Workbench and is downloaded as a vsix. (i.e. can be downloaded from within the VS UI.)

Mike Gale
  • 311
  • 2
  • 8
  • It's unfortunate that it makes editing files over 200 lines insanely, slow, though. I had to give up on this when I tried it. – Julian Birch Nov 05 '11 at 02:03
1

I'm only putting this in only as an answer to the more general implied question for "How can I try" tools that don't normally run on Windows or have yet to be ported. Use a virtual machine running a UNIX-like OS such as Linux or BSD.

Provided you have enough RAM and are willing to learn enough to get around, it will make trying open source software a lot easier. In the CoffeeScript case you can still do things like --watch on a shared folder and remain in Windows land most of the time. You also won't pollute your system with tools and services you try and don't buy into, which is handy if you do that a lot.

jerseyboy
  • 1,298
  • 13
  • 13
0

Consider using Chocolatey to install http://chocolatey.org/packages/CoffeeScript on Windows.

(Installing Chocolatey : https://github.com/chocolatey/chocolatey/wiki/Installation)

Andre
  • 139
  • 1
  • 6