How to use npm with node.exe?
Asked Answered
G

10

112

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

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

Gt answered 4/9, 2011 at 15:13 Comment(3)
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.Crosslink
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).Hugely
there is a bug. see #25093776Alkoran
G
39

npm can be downloaded (without installation) from here:

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

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

Gt answered 10/4, 2013 at 11:46 Comment(6)
Just extract the archive in the same folder as node.exe, so that npm.cmd is at the same level as node.exe.Downpipe
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...Kerrill
@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.Xenos
@Ezward, You don't need them in the same folder. See comment above.Xenos
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.Kerrill
If you are looking at this years later, you need to download instead from github.com/npm/cli/archive/refs/heads/latest.zipBin
M
63

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.
Manvil answered 20/2, 2012 at 18:27 Comment(5)
As of Feb 25, that bug seems to be fixed; I can run npm from %path% (either that or iisnode fixed it for me)Pyramidon
To use NPM on Windows, use the Node.js Command Prompt. Just trying to run npm from any other command line won't work.Fulgurant
Good list of modules for beginners. Instead of using plain Tedious, use node-mssql to wrap Tedious for a much easier api.Rempe
I had to manually create the directory/folder C:\Users\kevitt\AppData\Roaming\npm just now before I could install my first package.Esperanzaespial
@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. #facepalmIronwood
G
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.

Gaptoothed answered 29/3, 2015 at 16:50 Comment(2)
best answer for now. the best voted one got a broken link.Hautegaronne
Great answer. Only change - npm has moved its release here: Latest Direct downloadBin
G
39

npm can be downloaded (without installation) from here:

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

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

Gt answered 10/4, 2013 at 11:46 Comment(6)
Just extract the archive in the same folder as node.exe, so that npm.cmd is at the same level as node.exe.Downpipe
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...Kerrill
@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.Xenos
@Ezward, You don't need them in the same folder. See comment above.Xenos
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.Kerrill
If you are looking at this years later, you need to download instead from github.com/npm/cli/archive/refs/heads/latest.zipBin
K
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.

Korikorie answered 16/3, 2012 at 12:18 Comment(2)
where to download that msi? i don't see it on website.Sport
@vee, Isn't it right on the main page nodejs.org/download . Search for "msi".Xenos
R
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!

Rafaelita answered 5/9, 2011 at 8:45 Comment(5)
cygwin should never be the answer. It's the wrong way to solve these problems.Haldes
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.Rafaelita
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.Jabon
@TroyHoward I would go a step further and say that Windows should never be the answer for any sort of web development.Patti
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.Forenamed
S
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.

Standoffish answered 10/3, 2015 at 0:59 Comment(1)
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.Leroylerwick
R
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

Rempe answered 7/1, 2014 at 19:55 Comment(2)
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 ? )Sheugh
You can edit your own comments after you post them, within a 5 minute window. meta.stackexchange.com/questions/459/… . It seems now that you can at least delete the first two comments.Rempe
C
2

Here is a guide by @CTS_AE on how to use NPM with standalone node.exe: https://mcmap.net/q/82943/-how-to-resolve-39-npm-should-be-run-outside-of-the-node-repl-in-your-normal-shell-39

  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
Clarsach answered 11/11, 2015 at 13:12 Comment(0)
L
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.

Luggage answered 22/5, 2016 at 16:47 Comment(0)
C
-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.

Cacodyl answered 25/11, 2018 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.