Node.js and CoffeeScript on Windows, Redux
May 27
Remember back when we installed Node.js on a Virtual Machine just to get it working on Windows 7? Well there’s a better way.
1) Install Cygwin
Grab Cygwin from here and install that puppy. Make sure you install the following modules:
- Devel -> gcc4-g++ [Builds v0.4.2 and earlier use gcc-g++]
- Devel -> git
- Devel -> make
- Devel -> openssl-devel
- Devel -> pkg-config
- Devel -> zlib-devel
- Editors -> nano
- Libs -> openssl-devel
- Python -> python
Ensure you allow Cygwin to install required packages as well, otherwise these things just won’t work.
2) Download and build Node.js
$ cd ~
$ git clone git://github.com/joyent/node.git
$ cd node
$ git fetch --all
# if the above fails complaining --all is not recognised, try: git fetch origin
$ git tag
$ git checkout [latest stable tag from previous command, e.g., v0.2.5]
$ ./configure
$ make
$ make install
If, during the “configure” step, you get the following error: “error: could not configure a cxx compiler!” Do the following:
- Close your Cygwin terminal.
- Start -> Run -> ash
- /bin/rebaseall
- Close ash, re-open your Cygwin shell, and try again.
3) Configure Node.js
Node.js tries to use /etc/resolv.conf for domain name resolution, all pretending like its on Linux. Simple enough to get around though, just “nano /etc/resolv.conf” to create it. Slap the following in there:
nameserver 8.8.8.8
nameserver 8.8.4.4
Hit Ctrl-O to save. Now Node.js will route DNS requests through Google’s free DNS service.
4) Install NPM
This one’s easy. Run this:
curl http://npmjs.org/install.sh | sh
5) Install CoffeeScript
This is easy because we installed npm:
npm install -g coffee-script
6) Configure your system’s PATH
Open up Control Panel and search for PATH. Click on “Edit the system environment variables”, then click the “Environment Variables” button. Scroll through the “System Variables” list until you find “Path”, then add this to the end:
c:\cygwin\usr\local\bin
If you installed Cygwin to a different spot, make that modification now.
Ta-daa!
Congratulations! Node.js and CoffeeScript are now installed in Cygwin under Windows 7. You can call node.js from a cmd.exe window now due to that PATH variable, and even calling CoffeeScript is super-easy:
node /usr/local/lib/node_modules/coffee-script/bin/coffee {arguments}
Thanks to the offical guide on how to install CoffeeScript on Windows, and to the authors and maintainers of Node.js and CoffeeScript as well.
