I am Hack Sparrow
Captain of the Internets.

Install Node.js and NPM on Windows

How to install Node.js and NPM on Windows

UPDATE Feb 1, 2012: This article is fairly outdated now. Node.js installs right into the Windows system now, no need for moving files, setting path etc. If Node path is not detected, do a restart.

UPDATE: NPM now comes bundled with Node.js which can be installed using an MSI - get it here. No more headache of installing NPM separately on Windows.

Well, Node is not very Windows-friendly as of now; meaning - getting Node.js and npm working on a Windows machine is not as easy and straightforward as it is on a Linux machine. But worry not, getting a working Node environment is not that difficult either. I will show you the easy way, if you looking for installation from from source etc, look somewhere else.

Node.js on Windows

Getting Node on Windows is very easy, just download the node.exe binary from node.org. It's about 4.9 MB, doesn't take much time. Once downloaded, move node.exe to C:\node\node.exe, cd to C:\node, and do the following:

C:\node> set path=%PATH%;%CD%
C:\node> setx path "%PATH%"

The above commands set up Windows such that you can call node from anywhere in the system.

NPM on Windows

The npm dude is supposedly working on a one-line npm installer for Windows like we have for Linux. Till that's done the following is how you get npm working on a Windows machine.

Important: you might have thought / heard of manually downloading node modules, including npm itself, and getting them to work with Node. I tried manually installing npm from it's zip download but ended up with "Cannot find module 'graceful-fs'". Turned out, all the directories under node_modules were empty! Dependencies and all the hassle, working that way is a pain the ass and you will only end up wasting your time, so don't bother.

If you don't have Git installed on your system, the first step to installing npm on your system is installing Git. It's worth it, it will come handy in future for many other projects to, so go ahead download Git for Windows and install it.

I thought the Git installer would be smart enough to set the environment variables for the current session, but it didn't. You have to restart your computer to get Git working properly.

Once you have restarted you system and gotten Git working, cd to C:\node, and do the following:

C:\node> git config --system http.sslcainfo /bin/curl-ca-bundle.crt
C:\node> git clone --recursive git://github.com/isaacs/npm.git
C:\node> cd npm
C:\node> node cli.js install npm -gf

The cloning process takes some time, so be patient. Once you have installed npm, try installing a Node module, say express.

C:\node> npm install express -g

So that's it! That's how you get Node.js and npm working on your Windows machine. If you encounter any problem while installing them the way I described, ping me in the comments.

40 Responses to “Install Node.js and NPM on Windows”

  1. Benny Neugebauer says:

    Thank you!!

  2. undertaker says:

    Thank you very much about such wonderful topic\

    still need help please

    every thing was ok until this step “node cli.js install npm -gf”

    I have got this list of errors masseges

    http://img513.imageshack.us/img513/486/17069751.jpg

    can you help me with that please ?

    thanks and regards

    UnderTacker

  3. anix says:

    i was trying a socket io sample from internet but i has asked me for redis module.
    but npm is unable to install it on radis mobile.

    is radis available for windows or only for linux platform.

  4. Captain says:

    Hi anix, Redis is officially not supported on Windows, but there efforts to bring Redis to Windows – http://redis.io/download. Use VirtualBox to install Ubuntu and play around in a more developer friendly environment.

  5. Forgot says:

    No luck here I’m afraid

    node cli.js install npm -gf

    module.js:340
    throw err;
    ^
    Error: Cannot find module ‘c:\code\npm\cli.js install npm -gf’

  6. Forgot says:

    NPM doesn’t get bundled, I just installed nodejs from the installer you reference and typing “node” on the command line works
    Typing “npm” doesn’t

  7. Captain says:

    Windows is crazy. You will need to restart your system to make the node command available at the command line.

  8. Arun says:

    Sharing my experience in tiding over a few bottlenecks on a Windows system (2012). Perhaps this might help.

    I kept getting errors in the step:
    C:\node> node cli.js install npm -gf

    After a few trials (due to errors), I successfully got past that step *after* copying the node.exe file to the same location as cli.js. Iif you followed the step before, that would be the folder where npm repository was downloaded to. To recollect, the previous step was:
    C:\node> cd npm

    Thanks for this write-up! EVen though you have commented in highlighted text on the availability of installers, I like the manual route, just so that it is transparent to me.

    BTW, I am guessing you missed the “/m” option in the SETX command, was it deliberate? Without that, I guess the setting (for path env variable) only goes to the logged in user.

  9. pistolla says:

    im encountering an error
    npm err error invalid protocol
    probably you could be having a solution post
    thank you

  10. Naga says:

    Hi while cloning i am getting the fatal please help me out .

    C:\node>git clone –recursive git://github.com/isaacs/npm.git
    Cloning into ‘npm’…
    fatal: unable to connect to github.com:
    github.com[0: 192.30.252.131]: errno=No error

    Thanks in advance.

Make a Comment