Package installed with npm is not available at command prompt

Asked

Viewed 979 times

2

I installed the nodejs v0.12.6 on my computer with windows but I had some problems.

The first one I found a solution in the internet very simple e I thought that everything would work normally however when trying to install some package, in this case the hex it installs perfectly but when trying to run the command it returns the following message:

'hexo' is not recognized as an Internal or External command, operable program or batch file.

But when accessing the directory of npm where the hexo was installed in my case C:\Program Files\nodejs\node_modules\npm and execute the command that initializes a blog using the hex:

hexo init blog

Inside this directory:

C:\Program Files\nodejs\node_modules\npm>hexo init blog
INFO  Copying data to C:\Program Files\nodejs\node_modules\npm\blog
INFO  You are almost done! Don't forget to run 'npm install' before you start blogging with Hexo!

It installs and generates the files perfectly.

Is there any way to fix this? Because I need it to recognize the command regardless of which directory I am in, because in the npm is not a suitable place.

1 answer

1


To be able to access from anywhere, you would need to have done a "global" installation of the module:

npm install -g hexo

This works if the location where npm installs the global modules is available in your Windows PATH. Check if this environment variable contains C:\Program Files\nodejs\npm\node_modules, otherwise include this value in the list.

However, attention to official recommendations on when to install globally:

  1. If you are installing something that will use ewm your program, with require('whatever'), install locally at the root of your project.
  2. If you are installing something to use in the shell, on the command line, install globally so that binaries are placed in an available location in your PATH environment variable.

Your case even seems to be the (2).

  • I had installed globally earlier, removed now and reinstalled to see if I had forgotten something but apparently not. Still not recognizing as you can see in the image: http://i.imgur.com/tJjgPRA.png but inside npm works correctly: http://prntscr.com/7pzdmw

  • Well, when checking the environment variables the path where the modules get installed were not available. Just add the full path C:\Program Files\nodejs\node_modules\npm and it worked perfectly, because as it was C:\Program Files\nodejs does not work. Please add your reply and I will mark it as correct and thank you very much.

  • In a way I had already mentioned that the path needed to be in the PATH, but I edited to make it clearer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.