Writing Node.js Apps on Windows 8

Yeah, I know. Real men don’t program on Windows–let alone Windows 8. Whatever. Node runs fine in Windows, and I do build node apps on it, but there are few things I’ve had to deal with. If you’re using Windows, go for it. Just be a little careful.

First, I open a few command windows in Administrator mode. Then I start mongo in one, and–if I’m running BDD tests–selenium server in a second. Now comes the dangerous part. If you want to run any npm or grunt commands, you have to first issue the command ‘set NODE_PATH=.’ at the command prompt. Yes, that is a decimal point (aka period) at the end, and I always run this from the root directory of my node project. You have to do this once in each command window you are going to use. Failing to do so can be catastrophic when using NPM. I once ran npm install (which should reinstall everything in the package.json file) without setting this environment variable; It was a complete mess–packages got installed all over the place, nesting so deeply that the file paths exceeded 250 characters in length, meaning that the parent directory couldn’t simply be deleted and forcing me to resort to time-consuming and tedious efforts to eradicate the miscreant packages piece by piece. What joy!

Since I’m lazy, forgetful, and don’t get to code that often, I create .bat files for many tasks, and include the set commands that I need. I do this because I have multiple projects, and have been moving back and forth between them with regularity–using the .bat files prevents me from forgetting one of these little details and doing something stupid. Here’s an example. It’s called rungrunt:

set NODE_ENV=%1
set NODE_PATH=.
grunt

I have others called runtest (for mocha tests), runcover (for code coverage), etc.

Advertisements

About jeffmershon

Director of Program Management at SiriusXM.
This entry was posted in Software and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s