Today we’ll be installing Node.js and CoffeeScript on Windows (I have described earlier how to do it on Ubuntu Linux). My Node.js installation routine is loosely based on this document.
Here is one catch I have to explain first. A version of Node.js for Windows does exist . However it is described by its authors as experimental one and it is not recommended for running CoffeeScript compiler. What’s more, IMHO it will likely always lag behind Linux/Unix version of Node.js. The reason is following. Authors of Node.js aim at creating a very fast technology for networking applications. Naturally, to achieve this they rely heavily on low-level OS capabilities and they have chosen to use POSIX API for this purpose. POSIX stands for Portable Operating System Interface for Unix; all versions of UNIX and most versions of Linux implement it; Mac OS X is POSIX-compliant as well and as you can see here Ryan Dahl (“father” of Node.js) uses Mac laptop for development. There are other POSIX-compliant OS as e.g. AIX.
However Microsoft decided not to make Windows POSIX-compliant. Yes, one can figure out how to do the same things (more or less) using Windows API, but still this requires major changes in the code. Maintaining two widely different code bases ( e.g. of Node.js) and evolving them in parallel is quite difficult and expensive. So do not count on “native” Windows version of Node.js, at least for now.
[Update on Sep 27, 2011. If you just want to compile CoffeeScript on Windows and do not need latest and greatest Node.js for other purposes, you can do it in much simpler way than I describe below. See details here. But a lot of advance functions of CoffeeScript compiler won't work or would require tweaking to make them working. If you want to use latest and greatest Node.js on Windows and/or fully functional CoffeeScript compiler and Cake build tool, follow the instructions below].
We’ll use an existing work around of the problem to install and to run POSIX version of Node.js on Windows. Obviously, Node.js is by far not the first application which face a problem due to Windows being not POSIX-compliant. There is Cygwin which is a combination of DLL providing emulation of POSIX API on Windows and a set of POSIX-compliant software like e.g. Bash shell etc. Being installed on Windows Cygwin provides a sort of POSIX environment for other applications that need it to run.
So we’ll run Node.js on top of Cygwin. To do this we need to install Cygwin first. Here are original Cygwin installation instructions if you want to follow them. Otherwise just do what I describe.
Download Cygwin setup.exe and run it. It launches Cygwin installation wizard. On the second screen select “Install from Internet”.
Click “Next”. Accept all default values on screen #3:
Click “Next”. Enter c:\cygtemp ( or whatever temporary directory you like) as Local Package Directory on screen #4:
Click “Next” and agree on creating the directory. Screen #5 asks about details on your Internet connection:
If you are doing this at home, you almost certainly don’t have a proxy, so select “Direct Connection”. If you are within LAN (e.g. a corporate network), then you the most likely have a proxy and you can try “Use Internet Explorer Settings” or just enter proxy URL and port. Click “Next”.
Screen #6 offers you to choose a URL to download binaries from:
Select any HTTP URL which you like (certain networks block FTP) and click “Next”. Click OK to setup alert dialog. The next screen suggest you to select packages you want to install:
- Expand “Devel” section and select:
- gcc (the one which is labeled as “gcc: C compiler upgrade helper”),
- openssl-devel
- make
- zlib-devel
- Expand “Net” section and select:
- curl
- openssl
- Expand “Python” section and select python.
Click “Next”. The next screen will show you what additional packages will be downloaded as dependencies to the ones you selected:
and the download will start:
At this moment you can go and make coffee for yourself. The installation will take time to compete.
Next you will see this screen:
Select both checkboxes and click “Finish”. Congratulations, we have installed Cygwin.
Now go to Start->All Programs->Cygwin. Click Cygwin Bash Shell. This will launch Cygwin terminal window with Bash Shell:
First we have to make DNS resolution working for Cygwin. To do this we have to add DNS servers to Cygwin resolv.conf file. Type this:
echo 'nameserver 8.8.8.8' >> /etc/resolv.conf echo 'nameserver 8.8.4.4' >> /etc/resolv.conf
This adds Google Public DNS servers to your Cygwin configuration.
Re-start Cygwin terminal window. Type which gcc. If you see /usr/bin/gcc as a response, we are done with installing Cygwin.
If you want to just copy and paste the Bash commands I will be describing below into Cygwin terminal window, you can do it this way: right-click on Cygwin terminal window title bar and select Edit from the context menu:
Click Paste and the text you have copied previously will be pasted in Cygwin window.
Make sure you are in the home directory. Type this:
cd ~
Create a directory where Node.js will be installed:
mkdir nodejs
Add the directory to Cygwin PATH:
echo 'export PATH=$HOME/nodejs/bin:$PATH' >> ~/.bashrc
Download and unzip Node.js source. To do this check URL for downloading the latest stable Node.js source. You can find it here. At the moment when I’m writing this post the URL is http://nodejs.org/dist/node-v0.4.11.tar.gz . Substitute your URL into the command below and type it into Cygwin terminal window:
curl http://nodejs.org/dist/node-v0.4.11.tar.gz | tar xz
This will create a directory with Node.js source in it. Check the name of the directory. Type ls node*. You are going to see something like this:
node-v0.4.11 nodejs
This means the source directory name is node-v0.4.11 (nodejs is the directory you have created earlier).
Go to this directory:
cd node-v0.4.11
Configure make build by typing:
./configure --prefix=~/nodejs
You should see at the end of output:
'configure' finished successfully (10.953s)
If the attempt failed, check whether you installed all additional Cygwin components I have mentioned above. For this just run Cygwin setup.exe and go through the steps described above. This won’t destroy your existing Cygwin, but it will add whatever you forgotten to add. Re-start Cygwin, and go to the source directory by typing cd ~/node-v0.4.11. Run the configuration command again.
After you executed the configuration command successfully, execute Node.js build:
make install
When the build ends you should see something like this:
'install' finished successfully (5m54.802s)
Now install NPM (Node.js Package Manager):
curl http://npmjs.org/install.sh | sh
The script will ask you if you want to do cleaning. Answer yes. If all goes OK you will see the message:
It worked
Now let’s verify whether Node.js works. Type node. You should see > as a prompt. Type 2+2. If the reply is 4, Node.js works.
It’s time to install CoffeScript. Type
npm install -g coffee-script
in the terminal window. You should see a message like this at the end of the output:
coffee-script@1.1.2 /home/vlad/nodejs/lib/node_modules/coffee-script
which means CoffeeScript has been installed.
Now let’s verify that CoffeeScript works. Type this:
echo "square = (x) -> x * x" > test.coffee coffee --compile test.coffee cat test.js
You should see this:
(function() {
var square;
square = function(x) {
return x * x;
};
}).call(this);
Congratulations! Node.js and CoffeeScript are installed and ready to be used.
Now let’s have some fun with Node.js after all this hard work
Create (using Notepad editor or any other text editor) a new JavaScript file named webserver.js and put this code in it:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
Save the file in Cygwin home directory (in my case it is c:\cygwin\home\vlad; substitute your user name). Then type in the terminal window:
node ~/webserver.js
You will see this message:
Server running at http://127.0.0.1:8080/
Open your browser and point it to http://127.0.0.1:8080/. You should see Hello World message in the browser. Congratulations! You have just written a web server in JavaScript using Node.js. Isn’t that cool?
Advice on how to use CoffeeScript on Windows.
Windows files can be accessed from Cygwin. Let’s suppose you put your test.coffee file which you want to compile into c:\dev\coffee Windows folder. The corresponding Cygwin file will be /cygdrive/c/dev/coffee/test.coffee. This means to compile it you should type in Cygwin terminal window:
coffee --compile /cygdrive/c/dev/coffee/test.coffee
The result of the compilation will be placed in the same folder where test.coffee is located.
See more details on accessing Windows files from Cygwin here.
To avoid typing long paths you can create a symlink which will be pointing to a folder where you keep your CoffeeScript files. Let’s suppose again that your CoffeeScript files are in c:\dev\coffee folder. Type this in Cygwin terminal window:
ln -s /cygdrive/c/dev/coffe cf
Of course, you can use any valid directory name instead of cf to name the symlink. Now you can access your CoffeeScript files using the symlink with much shorter path:
coffee --compile cf/test.coffee
That’s all for today.











Hi Vlad,
Do yo think the above instruction works for Windows 7?
Regards,
Papitha
Papitha,
I did not test it on Windows 7 (I use old Windows XP when I need Windows, in all other cases I use Ubuntu Linux), so I can just speculate. I think the key issue here is to install Cygwin successfully. As soon as Cygwin is installed, you can follow my instructions above.
Cygwin team implemented support for Windows 7 since Cygwin 1.7, so make sure you use version 1.7 or later. Here ( http://www.sysdigg.com/run-and-install-cygwin-on-windows-7-ultimate ) are instructions on how to install Cygwin on Windows 7. Please let me know how it worked for you.
You may want to look at a simpler approach to using CoffeeScript on Windows which I described here: http://vladnevzorov.com/2011/09/23/running-coffeescript-on-windows-for-those-who-need-just-basic-compilation/. It will likely work for Windows 7 as well.
Vlad,
Yes, followed your instructions with Cygwin and it worked on XP.. but failed with windows 7.. that’s ok.. Thank you so much for this clear instructions on how.. AWESOME!!
Regards,
Papitha
Vlad, I follow every step of you excelent guide. The version I downolad is v-0.6.8. when I try the ./configure.. it returns a message “cygwin not supported”
I´m using winxp SP3.
Don´t know how to proceed
Thanks in advance
Mauro M.
Mauro,
I will look at that and I will reply in few days.