Node.js is an evented system, that allows JavaScript developers to write fast, non-blocking, applications that run independent of the client and have access to aspects of the underlying operating system such as the file system.
Installing Node.js on systems such as Linux or Mac OSX is straight forward and simple but, installing it under Windows is a little more tricky, that is until the port of Node.js to Windows is complete, allowing Node.js to run natively on Windows.
Your first step is to download and install Cygwin. For Nodejs you can grab the zip archive (remember, even numbers = stable releases, uneven numbers != stable) or you can clone the repository directly from Github. I am using the clone route for this article.
Getting Cygwin Ready
Whether you are going to work from a clone using Git or not, we need to step back for a little bit and add a couple of additions to Cygwin before we can continue. To install extra features run the setup.exe file you downloaded when initially installing Cygwin. Once you get to the select packages window, type git into the search input.
From the result, open up the develop tree and select git and git-completion(optional):
Next type in python, open up the interpreters tree and select the Python interpreter:
Next we need to add a C++ compiler, type g++ into the search input, open up the develop tree and select gcc-g++
We also need to add the openssl-develop package. Type in openssl, expand the Develop tree and select openssl-develop
Lastly, we need the all important make utility. Type make into search, expand the Develop tree and select make from the list:
Accept the required packages and click next again. Once the installation is complete, we can continue.
Getting The Nodejs Source
Open up Cygwin again and navigate to the directory you want to clone Nodejs to:
cd /cygdrive/c/github/
Now run the following command to clone the repo:
git clone https://github.com/joyent/node.git nodejs
After this is complete, move into the nodejs directory. We now need to checkout the version we want to build so, instead of just a plain checkout, we will specify the version we want:
git checkout v0.4.12
NOTE: If you have AVG AntiVirus installed it is going to mark the above process as a possible virus and prevent the checkout from happening successfully. Head into the AVG preferences and under ‘Resident Shield’ add an exception that points to the path where you Nodejs source will be located.
Building Node
Once the checkout is complete, run:
./configure
NOTE: If when running the above command you get an error stating “unable to remap…….”, you will need to rebase. To do this, close your current Cygwin window and open the Windows command prompt.
From here navigate to the bin directory inside Cygwin, for example
c:/cygwin/bin
From here run ash.exe. At the resulting bash, type /bin/rebaseall
Now, open up your Cygwin shell again and rerun configure. Once completed, run make and lastly run make install. Once this is DONE, you have a Nodejs environment on Windows.
Testing Our Installation
To test that our environment does indeed work, let’s use the staple Hello World example from the Nodejs site. In a folder anywhere on your computer, create a new file and call it hello.js, inside this, add the following:
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
Now, navigate to this file location using Cygwin and run the following command:
node hello.js
If you get a response such as “Server running at http://127.0.0.1:1337/”, Nodejs is working. For more proof, open up that URL and stare in amazement. And that is it, a working Nodejs installation on your Windows machine, enjoy!
I will be following this article up with a short one on setting up NPM, the Nodejs package manager, on Windows. On a side note, there is currently a native node.exe installer for Windows but, this is in the unstable 0.5.8 branch so, although I have been told it should be fine for testing and local development, if you wanna live on the edge, give it a go.
jmdesp wrote on :
Schalk Neethling wrote on :
Oskar Eriksson wrote on :
Schalk Neethling wrote on :
Oskar wrote on :
Schalk Neethling wrote on :
Oskar wrote on :