Node.js on Windows
Here’s what I ran through…
Update 18th July 2011: The latest official builds of node.js now come with a Windows executable. This is thanks to support from Microsoft.
Cygwin Cygwin gives you a full POSIX environment on Windows. It’s great for running apps designed for Unix, but it’s pretty heavy and not very … Windows-ey. It’d be like creating a “My Documents” folder on Ubuntu. All that being said, it’s the simplest and most reliable way of getting node running on Windows. Works for 0.2.6 -> 0.3.1 and 0.4.0+. Anything between 0.3.1 and 0.4.0 won’t compile. The steps (and common pitfalls) are well documented at https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows) Once you’ve got it running in Cygwin, if you jump out to a standard Windows command prompt and run c:\Cygwin\usr\local\bin\node.exe you’ll get a nice big error. More on this later.
MinGW The next step up from Cygwin is to compile it under MinGW. MinGW (Minimal GNU for Windows) provides the bare minimum set of libraries required to make it possible to compile Unix-y apps on Windows, avoiding the full POSIX strangehold environment that Cygwin provides. Works for 0.3.6+. Again, there are well documented steps for this: https://github.com/joyent/node/wiki/Building-node.js-on-mingw Once you’ve got it running in MinGW, jump out to a standard Windows command prompt again and run c:\wherever-you-put-your-git-clone\node.exe you’ll get a nice big error.
Standalone Now that we’ve compiled it with MinGW (you did that in the last step, right?) we’re ready to run it on Windows natively. From a native Windows command prompt: Create a new folder (mkdir node-standalone) Copy in the node.exe you compiled in MinGW (xcopy c:\wherever-you-put-your-git-clone\node.exe node-standalone) Copy in the MinGW helper libraries (xcopy c:\mingw\bin\lib*.dll node-standalone) Run node-standalone\node Voila! It works!
Running as a Service
Next up, I wanted to host node as a service, just like IIS. This way it’d start up with my machine, run in the background, restart automatically if it crashes and so forth.
Here are the commands I used to setup an instance of the SydJS website as a service:
nssm.exe install sydjs-node c:\where-i-put-node-standalone\node.exe c:\code\SydJS\server.js net start sydjs-node
What We Achieved
We now have node.js, running natively on Windows, as a service. Enjoy!
(Just please don’t use this in production – it’s really not ready for that yet.)