NodeJS on Win localhost

10 January 2012

While working on a proof of concept I thought this would be an ideal opportunity to try out NodeJS. It is a weird thing to fathom, writing server side Javascript but once you’ve spent some time with it, it will start to make more sense. Now I’m not a heavy server side programmer, on the contrary I normally shy away from this sort of thing but it is always good to know how to set up your own site at least. Anyways this is more of a reminder to myself to quickly get up and running should I ever use NodeJS with an M$ platform again.

Step 1

Download NodeJS from the site. Extract the MSI installer and execute it. Let it do it’s thing and all is good.

Step 2

Open up the command line.

Windows Key > Run > type in *cmd*

Or

Start > Run > type in *cmd*

Step 3

We need to install some helper modules which will take care of the scaffolding when we create a new web application. Execute each of these commands one at a time or if you feel confident chain them by appending two && signs.

C:> npm install express
C:> cd c:
C:> mkdir www-nodejs
C:> cd www-nodejs

The first line simply installs the Express module for NodeJS. The second changes the directory to the root of the filesystem identified by C. Create a new directory and call it www-nodejs. Move the cursor into this newly created directory by executing the last command. Of course the directory can be wherever you want it to be, I simply create it in the root for brevity and ease of use.

Step 4

Create the project and files needed. Express will create all the bare necessities. It is important to run the third command as you need to make sure you project has all the NodeJS dependencies it may require.

C:www-nodejs> express example-project
C:www-nodejs> cd example-project
C:www-nodejs> npm install -d
C:www-nodejs> node app.js

The last command will run the application. Browse to http://localhost:3000 to see your index page. If it isn’t located at localhost:3000 then open up app.js and look for the location. It simply means NodeJS runs on a different port than 3000.

Et Voila! HES6PYSQWCHK

Resources

13 March 2012 | Russell

You should add the note that npm install -g express should be used to access the command globally.

Also, I had to add npm to my PATH to get the npm command to work. using Windows 7 64bit.

Incorrect please try again