Thanks to Sharkie’s ongoing organisation efforts, SydJS is a thriving monthly JavaScript meeting here in Sydney. This evening they welcomed me along to talk about Node.js on Windows. Afraid of a mostly non-Microsoft crowd I rocked up with all the anti-Unix jokes I had but they turned out to be all quite friendly and it was a fun little talk.
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\nodeVoila! 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.
This is where nssm, the non-sucking service manager, enters the picture. This tool lets you host a normal .exe as a Windows service.
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.)
Thanks! This convinced me not to be afraid to try to build it myself.
Unfortunately, the latest code from GitHub doesn’t compile. =(
https://github.com/joyent/node/issues/775
Switching to the v0.4 branch does compile, though. After that, everything worked just as you wrote.
The guide needs to be updated for 0.4.3+. Uninstall gcc-g++ and install gcc4-g++, make distclean, ./configure, make and you should be back on track.
ugh, wrong problem, sorry.
I tried this a while back with no luck. Ended up just running VirtualBox (free) and running node in a small linux VM instead.
Very cool! Thanks Tatham.
Tatham,
As your readers are primarily a .NET crowd, can I suggest that next time you write a non-standard (i.e. non windows) type article, you please provide a bit of background – what is Node.js, why would we want it in the first place, and preferably a link to their site.
Ash
Good call Ash. In this case I just wanted to throw the resources up quickly while I was still at the group, but I’ll keep that in mind for future posts.
Hi Tatham, sounds like it was a great talk. Any reason why you didn’t use the windows binaries?
http://node-js.prcn.co.cc/
Thanks Tatham. Great info. I am part of Brisbane JS (brisjs.com) and it’s great to hear that you guys are doin cool stuff with Node down in Sydney.
Many Thanks Tatham. I’ve got standalone node.exe running in about half an hour. Quite impressive.
Is node-waf supposed to work in your setup? It seems I cannot get it working.
YAY. NODE.JS finally fr windows. i wud have “UPGRADED” to linux but i have no HDD left :P. TY very much!
I’ve been playing around Node.JS for a while. And it’s really a very good piece of technology. So I tried to build this simple Windows Installer package for NodeJS and some of its most common modules. You can check out my Google project page from here http://j.mp/nP3gDL.
Currently, the modules included are MySQL and Socket.IO because they’re the most used for my part. However, I’m working on to add many more modules as they’re tested to work perfectly with Windows. I hope someone can help me add more modules, until a package manager that is Windows Compatible arrives, but for the moment, I think this will do.
Additionally, i have pieced up this simple tutorial on how to add a simple chat system for an existing website (served by an existing web server such as Apache) by simply adding minimal code to the pages it serves and using NodeJS + SocketIO as another server to provide for asynchronous updates (e.g. chat) to the existing website. You can check it out on the wiki page of the project.
Legend, thank you for the NSSM tip. Was pulling my hair out and I wasn’t going to sleep until this was sorted. 😀
Is there any sample for Node with SQL Server 2008. I tried with Node-mssql but not working. Getting some error. Thx!
can ryppi be used as the package manager ?
This is one of the most informative information I’ve read. It really helps a lot. Thanks for sharing this and teaching some of your Idea’s
The overriding law of the empire was the Shari’ah, or Sacred Law, which as the
divine law of Islam was outside of the Sultan’s powers to change.
Granite Countertops Rockville MD
After eliminating duplications and choosing between contradictory statements, he issued a
single legal code, all the while being careful not to violate the basic laws of Islam.
Granite Countertops Virginia VA
For compiling on Windows 7. Download latest nodejs (version 6.8 at the time of this post) run the vsbuild.bat file in the root of the extracted folder. Several project files are created. Download C++ 2010 express from microsoft. Open the node.vcxproj and build. It compiled with only minimal warnings from the compiler.
I hope this helps someone. I looked through the node documentation without success
I want to run a simple webserver on port 3000 that starts when the computer starts.
When run directly via node it brings up the windows prompt “xyz is requesting network access”.
However, when installed as a service it fails silently and reports success.
Any idea how to pre-approve an app for network activity or to have prompt the user on startup?
This sounds like a Windows Firewall prompt. You can add an exception for either the executable, or the port, in Advanced Firewall settings.
When I stop the Windows service, how does the running node process notice this? (I’d like to shut my node child processes gracefully.) Thanks!
This is a really old, bad way to do this. You should now be hosting node.js in IIS, as per all of the official support.
The link to the NodeJS blog article is broken. Here’s the link: http://blog.nodejs.org/2011/06/23/porting-node-to-windows-with-microsoft%25e2%2580%2599s-help/
Got this work as last, great work!