26

When I run npm install -g <package> it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.

What can I do to fix this?

Thanks

Zain Rizvi
  • 21,625
  • 17
  • 82
  • 122

3 Answers3

35

I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm; to the user variable(since %AppData% dir is depending on user) PATH to fix it.

You will need to log out then log back in for the change to your PATH variable to take effect.

SET PATH=%AppData%\npm;%PATH%
M--
  • 18,939
  • 7
  • 44
  • 76
luochen1990
  • 3,124
  • 1
  • 16
  • 30
  • 3
    This worked like a charm. I did not have to log out and login though. I only restarted my command prompt which I would do anyway in order for the new `PATH` to load. – Suhas Feb 28 '17 at 19:29
  • what is meant by "user variable"? the current user PATH? – G.G Aug 02 '19 at 10:52
  • @G.G windows environment variable has two kinds, global variable & user variable. when I say "user variable", it means, not the "global variable". – luochen1990 Aug 07 '19 at 09:04
2

You have to run this line SET PATH=pathtonodejs;%PATH% (where pathtonodejs is where you installed nodejs) once the installation for nodejs is complete and it should work.

user3662697
  • 147
  • 1
  • 6
  • I had done that, but it turned out I had a separate issue. I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path – Zain Rizvi Jun 11 '14 at 20:57
0

It turned the problem was a change in behavior of the module I was using.

I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path

Zain Rizvi
  • 21,625
  • 17
  • 82
  • 122