Today I wanted to install NodeJS with Express on my Windows machine without having to compile anything on cygwin. Took me some time to find out how to do so easily. So here are those instructions for anyone else wanting to do so.
First, let’s create a dir to put everything in:
C:\Node
Install NodeJS
You can find pre-built and self-contained Windows binaries here: http://node-js.prcn.co.cc/. The latest stable is 0.4.11. Download that one and put everything in the Node folder. You should then have something like this:
C:\Node\bin C:\Node\lib ...
Install Express
Next up you install Express. That requires Mime and Connect modules. You can find all on GitHub:
- https://github.com/bentomas/node-mime.
- https://github.com/senchalabs/connect. I downloaded version 1.7.0.
- https://github.com/visionmedia/express. I downloaded version 2.4.3.
C:\Node\lib\node_modules folder. You should then have something like thisC:\Node\lib\node_modules\connect\... C:\Node\lib\node_modules\express\... C:\Node\lib\node_modules\mime\...
Test and Run
Create this file C:\Node\test.js and put this in:
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(80);
To run, open a command prompt, step into the Node folder and type:
bin\node.exe test.js
At this point, you may have this error:
Cannot find module 'qs'
If so, do a search and replace for ‘qs’ by ‘querystring’. That module was renamed in NodeJS, but Connect and Express may not have made the change yet. I had to change these 3 files:
- C:\Node\lib\node_modules\connect\lib\middleware\bodyParser.js
- C:\Node\lib\node_modules\connect\lib\middleware\query.js
- C:\Node\lib\node_modules\express\lib\http.js
After the search and replace, run again and the server should run without any errors. Now in a Browser type http://localhost and you should see Hello World.
That’s it! Now you can start developing a NodeJS web app directly from your Windows machine. How great is that!
Martin
Tags: Javascript, NodeJS
Ah, thought this was going to be a winner as I cant seem to get any other way to run node.js (cygwin).
Getting error:
C:\Node>bin\node.exe test.js
node.js:134
throw e; // process.nextTick error, or ‘error’ event on first tick
^
Error: EPERM, Operation not permitted
at HTTPServer._doListen (net.js:1106:5)
at net.js:1077:14
at Object.lookup (dns.js:153:45)
at HTTPServer.listen (net.js:1071:20)
at Object. (/test.js:6:5)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array. (module.js:421:10)
C:\Node>
Is there any ip settings that need changing?
In your “test.js”, try changing:
app.listen(80)
to any other port number, for example:
app.listen(3000)
then open
http://localhost:3000
This doesn’t work. The Express Framework is missing so many modules. I got up to the zlib modules and can’t find them.
Thanks for letting us know. We’ll be working on it.
Is there any good tutorial to install nodejs + express on windows 7?…
I have tried 2 web weblogs (http://www.planbox.com/blog/development/coding/getting-started-with-nodejs-on-windows.html) before asking this question, But I couldnt install Express framework properly….