51

I am new to node.js. I downloaded and install node.js installer from the official site. I have added this installer folder in PATH environment variable and I am able to run programs. But when I try to install some package using npm in node console it shows the error npm should be run outside of the node repl, in your normal shell. I also tried it on a separate console. But it shows command not found though I have added node in the environment variable.

enter image description here

enter image description here

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 1
    When you ran the installer, did you make sure that all of the "Add to PATH" options were selected/checked/installed? If so, you may have to restart your command prompt (close and re-open) if you had it open before the install, so that the PATH environment variable is updated. – mscdex Jun 29 '14 at 14:15
  • 1
    There was no installer like common windows installer. It's an exe file and when I double click it, it simply opens node console. – Aniket Thakur Jun 29 '14 at 14:20
  • Basically you need to run `npm` from a DOS window. Make sure npm is in the PATH (or just `cd` to the directory with `npm.exe` exists in `Program Files` – FractalSpace Dec 12 '16 at 00:52

9 Answers9

123

For Windows users, run npm commands from the Command Prompt (cmd.exe), not Node.Js (node.exe). So your "normal shell" is cmd.exe. (I agree this message can be confusing for a Windows, Node newbie.)

By the way, the Node.js Command Prompt is actually just an easy shortcut to cmd.exe.

Below is an example screenshot for installing grunt from cmd.exe:

enter image description here

James Lawruk
  • 30,112
  • 19
  • 130
  • 137
  • I would only add that the shortest way to run Windows Command Line is pressing Start button, and then writing **cmd** on the Search Box and pressing Enter – DavidTaubmann Jun 14 '16 at 16:25
  • 2
    Also don't forget to run it in administrator mode otherwise you'll get permission errors during installation. – Baz Guvenkaya Jul 05 '16 at 23:52
25

Do not run the application using node.js icon.

Go to All Programmes->Node.js->Node.js command prompt.

Below is example screen shot.

enter image description here

enter image description here

Aman
  • 433
  • 5
  • 11
14

If you're like me running in a restricted environment without administrative privileges, that means your only way to get node up and running is to grab the executable (node.exe) without using the installer. You also cannot change the path variable which makes it that much more challenging.

Here's what I did (for Windows)

  1. Throw node.exe into its own folder (Downloaded the node.exe stand-alone )
  2. Grab an NPM release zip off of github: https://github.com/npm/npm/releases
  3. Create a folder named: node_modules in the node.exe folder
  4. Extract the NPM zip into the node_modules folder
  5. Make sure the top most folder is named npm (remove any of the versioning on the npm folder name ie: npm-2.12.1 --> npm)
  6. Copy npm.cmd out of the npm/bin folder into the top most folder with node.exe
  7. Open a command prompt to the node.exe directory (shift right-click "Open command window here")
  8. Now you will be able to run your npm installers via: npm install -g express

Running the installers through npm will now auto install packages where they need to be located (node_modules and the root)

Don't forget you will not be able to set the path variable if you do not have proper permissions. So your best route is to open a command prompt in the node.exe directory (shift right-click "Open command window here")

CTS_AE
  • 12,987
  • 8
  • 62
  • 63
  • 1
    Because the git repo is outdated, I downloaded it from the new git repo: https://github.com/npm/cli, extracted and renamed to npm. Then from the step one, extracted "node-v12.6.0-win-x64.7z" and copied content into the new npm directory and ran the cmd command. I tried powershell first but it didn't work, normal cmd was ok. – Daniel Katz Jul 04 '19 at 07:43
11

It's better to use the actual (msi) installer from nodejs.org instead of downloading the node executable only. The installer includes npm and makes it easier to manage your node installation. There is an installer for both 32-bit and 64-bit Windows.

Also a couple of other tidbits:

  • Installing modules globally doesn't do what you might expect. The only modules you should install globally (the -g flag in npm) are ones that install commands. So to install Express you would just do npm install express and that will install Express to your current working directory. If you were instead looking for the Express project generator (command), you need to do npm install -g express-generator for Express 4.

  • You can use node anywhere from your command prompt to execute scripts. For example if you have already written a separate script: node foo.js. Or you can open up the REPL (as you've already found out) by just selecting the node.js (start menu) shortcut or by just typing node in a command prompt.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • Thanks for the info but could you tell how can I use npm command with my current setup? Is there a separate installer available for npm? – Aniket Thakur Jun 29 '14 at 14:35
  • 1
    There is no separate installer for npm (at least for Windows). It's included in the official msi node installer. – mscdex Jun 29 '14 at 14:38
6

As mscdex said NPM comes with the nodejs msi installed file. I happened to just install the node js installer (standalone). To separately add NPM I followed following step

  1. Download the latest zip file of NPM from here.
  2. Extract it in the same file as that of node js installer.
  3. If you have added the directory containing to node js installer to PATH env variable then now even npm should be a recognized command.
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 1
    I was having your same scenario downloading the portable node.exe file instead of using the .msi package. Thanks for this tip! – asgs May 01 '15 at 21:17
3

you just open command prompt, then enter in c:/>('cd../../') then npm install -g cordova enter image description here

Mosam Mehta
  • 1,658
  • 6
  • 25
  • 34
Aarji George
  • 599
  • 4
  • 8
2

It's simple. Press the Windows logo on your keyboard. Then, type node.js command prompt in the search bar and run it. screenshot: run npm outside node repl

Nick Alexeev
  • 1,688
  • 2
  • 22
  • 36
1

You must get directory right path of program(node.js in program files).

such as

enter image description here

and use "npm install -g phonegap"

NuuoeiZ
  • 94
  • 1
  • 4
0

enter image description here

Just open Node.js commmand promt as run as administrator

Prateek Yadav
  • 932
  • 6
  • 8