Windows and Node: Getting Started

Alex R. Young





tutorials node windows windows-and-node

Windows and Node: Getting Started

Posted by Alex R. Young on .

tutorials node windows windows-and-node

Windows and Node: Getting Started

Posted by Alex R. Young on .

I enjoyed writing the Unix and Node tutorials over the past few months, and I hope they got people thinking about creating Node programs that behave like first-class Unix citizens.

Since last June, when Microsoft partnered with Joyent to port Node to Windows, 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 Express web application to prove it's generally portable with existing Node modules.


My Windows desktop

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.

Downloading Node's Windows installer

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

Running the Node Windows installer

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.

Running Node

Running Node and npm

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:

Evaluating JavaScript

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:

Using npm

Getting Help

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.

Getting help

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

Hello World from Express

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 one of the many freely available editors for Windows.

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 Documents\Code\hello  
npm install  

Installing packages with npm

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:

Windows Security Alert


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 Windows Azure. I bought a Windows 7 license specifically to write this series, so I'm going to get my money's worth!