108

I have downloaded Windows Binary (.exe) of nodejs from the main page.

How can I install and use npm (Node package manager)?

Pacerier
  • 76,400
  • 86
  • 326
  • 602
TN.
  • 17,602
  • 25
  • 84
  • 141
  • The windows binary is 0.5.x, which is the unstable version of node.js. I recommend against running this in production, however it's usable for development. You may want to wait for 0.6 (soon!) before you run node.js in windows on production. – Raynos Sep 05 '11 at 10:14
  • 5
    If you find this question through google, Node.js for Windows comes with npm supplied (note: it's a script passthrough executable, not a true executable). – Mike 'Pomax' Kamermans Jul 08 '13 at 18:01
  • there is a bug. see http://stackoverflow.com/questions/25093276/node-js-windows-error-enoent-stat-c-users-rt-appdata-roaming-npm – gcb Dec 23 '14 at 22:26

10 Answers10

60

The current windows installer from nodejs.org as of v0.6.11 (2012-02-20) will install NPM along with NodeJS.

NOTES:

  • At this point, the 64-bit version is your best bet
  • The install path for 32-bit node is "Program Files (x86)" in 64-bit windows.
  • You may also need to add quotes to the path statement in environment variables, this only seems to be in some cases that I've seen.
  • In Windows, the global install path is actually in your user's profile directory
    • %USERPROFILE%\AppData\Roaming\npm
    • %USERPROFILE%\AppData\Roaming\npm-cache
    • WARNING: If you're doing timed events or other automation as a different user, make sure you run npm install as that user. Some modules/utilities should be installed globally.
    • INSTALLER BUGS: You may have to create these directories or add the ...\npm directory to your users path yourself.

To change the "global" location for all users to a more appropriate shared global location %ALLUSERSPROFILE%\(npm|npm-cache) (do this as an administrator):

  • create an [NODE_INSTALL_PATH]\etc\ directory
    • this is needed before you try npm config --global ... actions
  • create the global (admin) location(s) for npm modules
    • C:\ProgramData\npm-cache - npm modules will go here
    • C:\ProgramData\npm - binary scripts for globally installed modules will go here
    • C:\ProgramData\npm\node_modules - globally installed modules will go here
    • set the permissions appropriately
      • administrators: modify
      • authenticated users: read/execute
  • Set global configuration settings (Administrator Command Prompt)
    • npm config --global set prefix "C:\ProgramData\npm"
    • npm config --global set cache "C:\ProgramData\npm-cache"
  • Add C:\ProgramData\npm to your System's Path environment variable

If you want to change your user's "global" location to %LOCALAPPDATA%\(npm|npm-cache) path instead:

  • Create the necessary directories
    • C:\Users\YOURNAME\AppData\Local\npm-cache - npm modules will go here
    • C:\Users\YOURNAME\AppData\Local\npm - binary scripts for installed modules will go here
    • C:\Users\YOURNAME\AppData\Local\npm\node_modules - globally installed modules will go here
  • Configure npm
    • npm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"
    • npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
  • Add the new npm path to your environment's PATH.
    • setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"

For beginners, some of the npm modules I've made the most use of are as follows.

More advanced JS options...

For testing, I reach for the following tools...

  • mocha - testing framework
  • chai - assertion library, I like chai.expect
  • sinon - spies and stubs and shims
  • sinon-chai - extend chai with sinon's assertion tools
  • babel-istanbul - coverage reports
  • jest - parallel testing, assertions, mocking, coverage reports in one tool
  • babel-plugin-rewire - slightly easier for some mocking conditions vs. jest

Web tooling.

  • webpack - module bundler, package node-style modules for browser usage
  • babel - convert modern JS (ES2015+) syntax for your deployment environment.

If you build it...

  • shelljs - shell utilities for node scripts,. I used to use gulp/grunt, but these days will have a scripts directory that's referenced in package.json scripts via npm. You can use gulp tools inside plain scripts.
Tracker1
  • 17,841
  • 10
  • 75
  • 104
  • As of Feb 25, that bug seems to be fixed; I can run npm from %path% (either that or iisnode fixed it for me) – Dan Davies Brackett Feb 26 '12 at 04:47
  • 12
    To use NPM on Windows, use the `Node.js Command Prompt`. Just trying to run `npm` from any other command line won't work. – Daniel A.A. Pelsmaeker Feb 14 '14 at 19:28
  • Good list of modules for beginners. Instead of using plain Tedious, use [node-mssql to wrap Tedious](http://stackoverflow.com/a/22658512/1385429) for a much easier api. – Christiaan Westerbeek Jun 03 '14 at 21:05
  • I had to manually create the directory/folder *C:\Users\kevitt\AppData\Roaming\npm* just now before I could install my first package. – Kenny Evitt Aug 14 '14 at 14:33
  • @DanielA.A.Pelsmaeker I have **NEVER** ran `npm` *on Windows* with **Node.js Command Prompt**; not saying it's not a viable method. Almost any terminal or shell will work if the person using it knows what they are doing! I use `npm` commands almost every single day; and BASH is my go to if I'm stuck using Windows; but, Windows native CMD & PowerShell work, BASH, WSL (BASH, ZSH, Fish)... they all work just fine. "*Just trying to run npm from any other command line won't work.*" That statement is like saying you must use a VIM to write JavaScript and any other IDE won't work. #facepalm – Rockin4Life33 Sep 02 '19 at 04:32
43

When Node.js is not installed using the msi installer, npm needs to be setup manually.

setting up npm

First, let's say we have the node.exe file located in the folder c:\nodejs. Now to setup npm-

  1. Download the latest npm release from GitHub (https://github.com/npm/npm/releases)
  2. Create folders c:\nodejs\node_modules and c:\nodejs\node_modules\npm
  3. Unzip the downloaded zip file in c:\nodejs\node_modules\npm folder
  4. Copy npm and npm.cmd files from c:\nodejs\node_modules\npm\bin to c:\nodejs folder

In order to test npm, open cmd.exe change working directory to c:\nodejs and type npm --version. You will see the version of npm if it is setup correctly.

Once setup is done, it can be used to install/uninstall packages locally or globally. For more information on using npm visit https://docs.npmjs.com/.

As the final step you can add node's folder path c:\nodejs to the path environment variable so that you don't have to specify full path when running node.exe and npm at command prompt.

Ashish Uttam
  • 439
  • 4
  • 3
39

npm can be downloaded (without installation) from here:

http://nodejs.org/dist/npm/

https://github.com/npm/npm/releases

TN.
  • 17,602
  • 25
  • 84
  • 141
  • 9
    Just extract the archive in the same folder as node.exe, so that npm.cmd is at the same level as node.exe. – Ezward Dec 22 '13 at 04:18
  • 1
    This is a good way to "install" node and npm if you don't have Admin privileges. Once you have both npm and node there, add that to your path: `set NODE=%USERPROFILE%\nodejs` and `PATH=%PATH%;%NODE%` and you're good to go... – djKianoosh Sep 03 '14 at 21:39
  • @djKianoosh, That's abit roundabout. All you need is `set path=your/folder/containing/node`. For example, `set path=%userprofile%\nodejs`. Then call `npm` after that, that's all. The command `set path` only affects your current cmd session, not globally in the registry, so you don't have to undo it. – Pacerier Aug 11 '15 at 16:05
  • @Ezward, You don't need them in the same folder. See comment above. – Pacerier Aug 11 '15 at 16:08
  • that's right @Pacerier. I have something similar scripted to run on login to automate it. Main problem in an enterprise is the lack of admin rights and proxies/firewalls. – djKianoosh Aug 11 '15 at 16:14
11

I just installed latest version of node (0.6.12) in Windows 7 using msi (node-v0.6.12.msi).

npm is already shipped with it, no need to include it separately.

I was facing permission issue while running npm (npm install mysql), from the path where my nodejs resided, i.e. C:\Program Files (x86)\nodejs

Then I followed below steps:

1) Added C:\Program Files (x86)\nodejs\npm in environment variables - Path system variable.

2) went back to only C:\ in command prompt and gave the command - npm install mysql - and voila! it worked..

Hope this helps.

Prashant
  • 4,693
  • 9
  • 36
  • 56
7

I am running node.js on Windows with npm. The trick is simply use cygwin. I followed the howto under https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows) . But make sure that you use version 0.4.11 of nodejs or npm will fail!

malte
  • 187
  • 1
  • 4
  • 9
    cygwin should never be the answer. It's the wrong way to solve these problems. – Troy Howard Mar 01 '12 at 07:13
  • With node 0.6 you can use node easily under windows, but many node modules that depend on binaries don't support windows and then you come again to the point where you need something like an unix environment. – malte Mar 02 '12 at 08:47
  • 1
    Actually @Troy Howard you don't have to deal with Windows as much if you use cygwin. That alone is a huge plus because it eliminates the source of most of his problems. – JaneGoodall Apr 09 '14 at 21:06
  • 1
    @TroyHoward I would go a step further and say that Windows should never be the answer for any sort of web development. – Noz Feb 18 '16 at 16:17
  • A step further beyond your step to retort, Windows Visual Studio and .NET are fine for web development including PHP and Perl that all run on IIS. – Jules Bartow Mar 25 '17 at 12:18
4

I've just installed 64 bit Node.js v0.12.0 for Windows 8.1 from here. It's about 8MB and since it's an MSI you just double click to launch. It will automatically set up your environment paths etc.

Then to get the command line it's just [Win-Key]+[S] for search and then enter "node.js" as your search phrase.

Choose the Node.js Command Prompt entry NOT the Node.js entry.

Both will given you a command prompt but only the former will actually work. npm is built into that download so then just npm -whatever at prompt.

vijrox
  • 981
  • 1
  • 11
  • 33
rism
  • 11,221
  • 14
  • 70
  • 110
  • This resolved the question I came here for - *after* installing node.js on Windows via the MSI installer, I still could not access npm from the command line, and running in the "node.js" window just gave an error that I needed to *use* the command line. I was confident that I should not have to add paths manually - then I found that I needed to run in the special node shell, as indicated by this answer. Thanks. – Dan Nissenbaum Jun 11 '15 at 12:33
3

Use a Windows Package manager like chocolatey. First install chocolatey as indicated on it's homepage. That should be a breeze

Then, to install Node JS (Install), run the following command from the command line or from PowerShell:

C:> cinst nodejs.install

Christiaan Westerbeek
  • 8,817
  • 12
  • 54
  • 77
  • That did now work for me. The Path in windows 8.1 is set correctly to: C:\Program Files\nodejs. But I cant run npm unless I switch to that path. But If i ran the nodejs cmd line prompt it sets it so it works. It sets up C:\Windows\System32\cmd.exe /k "C:\Program Files\nodejs\nodevars.bat" and run in "C:\Program Files\nodejs\" Maybe the c:\> cinst nodejs did that That I ran before cinst nodejs.install . I am unsure. (why cant I correct an old comment ? ) – Patrik Lindström Jun 29 '14 at 19:32
  • You can edit your own comments after you post them, within a 5 minute window. http://meta.stackexchange.com/questions/459/should-we-be-allowed-to-edit-comments . It seems now that you can at least delete the first two comments. – Christiaan Westerbeek Jun 30 '14 at 07:42
2

Here is a guide by @CTS_AE on how to use NPM with standalone node.exe: https://stackoverflow.com/a/31148216/228508

  1. Download the node.exe stand-alone from nodejs.org
  2. Grab an NPM release zip off of github https://github.com/npm/npm/releases
  3. Create a folder named: node_modules in the same folder as node.exe
  4. Extract the NPM zip into the node_modules folder
  5. Rename the extracted npm folder to npm and remove any versioning ie: npm-3.3.4 –> npm.
  6. Copy npm.cmd out of the /npm/bin/ folder into the root folder with node.exe
Community
  • 1
  • 1
luff
  • 2,884
  • 1
  • 16
  • 9
0

I just installed Node.js for the first time and it includes NPM, which can be ran from the Windows cmd. However, make sure that you run it as an administrator. Right click on cmd and choose "run as administrator". This allowed me to call npm commands.

Sean
  • 239
  • 3
  • 12
-1

Search all .npmrc file in your system.

Please verify that the path you have given is correct. If not please remove the incorrect path.

J100
  • 2,808
  • 1
  • 7
  • 17