How to 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.execd toC:\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 aheaddownload 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.

你可能感兴趣的:(windows)