Thursday, January 9, 2014

Windows and Node: Getting Started

, Node has gone from strength to strength on Microsoft's ubiquitous OS. I thought it was only fair to give Windows the same treatment.

In Windows and Node, we'll take a look at Windows-centric Node development. In the first part, we'll install Node (which now includes npm), take a look at the basics, then make a little web application to prove it's generally portable with existing Node modules.


I'm running a pretty standard installation of Windows 7 Home Professional. I've got a few things I like installed (Steam, Putty, Chrome, Vim, Dropbox), but nothing specifically related to development. That means there's no compilers, Cygwin, or Visual Studio.

To download Node, go to , click "Download", and click "Windows Installer". This will give you a Windows Installer (MSI) file that will install Node and npm.

Running the Windows installer will show a wizard, it's pretty easy to follow. It's just like installing any other Windows program - the Node binaries will end up in C:Program Files (x86)nodejs, and will be accessible from cmd.exe.


To run Node, open a Command Prompt and type node. This will load the standard Node REPL where JavaScript can be evaluated. Here I've opened my win.ini using Node's fs module:

If you want to exit the REPL, I noticed that ctrl-d works (just like Unix!)

Similarly, npm can be run. The first time I used it to search for something, it took a few minutes to download the index first:


When I'm working in Unix, I often find myself reading npm's man pages. Windows doesn't have man, so instead npm will open a browser and display HTML versions of its standard help files.

The first time I tried this an error was displayed. However, there's a where fixes for the problem are discussed, and Isaac Schlueter stated that the problem will be fixed in Node 0.6.17.


Now that we've got Node and npm working it shouldn't take too much work to get a little project started. Make a new directory somewhere and open your favourite editor. I'm using Vim, but you can use .

Create a file called package.json:

"name": "hello"

, "version": "0.0.1"

, "dependencies": {

"express": "latest"

Then change directory to the location of your project in Command Prompt, and run npm install to install Express:

cd DocumentsCodehello

npm install

Make a file that contains a simple Express app, I called mine index.js:

var express = require('express')

, app = express.createServer();

app.get('/', function(req, res) {

res.send('hello world');


Then run it with node index.js and visit http://localhost:3000/ in a browser.

I got a firewall warning when I did this, but it was fairly self-explanatory:


On a standard consumer-grade version of Windows 7, Node can be installed and programs can be written without installing anything else. Building modules that require C/C++ compilation is a little bit more work, but community-favourite Express can be installed without any hassle.

In the coming weeks I hope to look at more detailed Windows-related issues, and working with Node and Microsoft technologies like . I bought a Windows 7 Ultimate license specifically to write this series, so I'm going to get my money's worth!


Alex Young
Full Post

No comments:

Post a Comment