Package installed with npm is not available at the command prompt

2

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

I first found a solution on the internet very simple and thought that everything would work normally however when trying to install some package, in this case the hexo it installs perfectly however 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.

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

hexo init blog

Within 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 files perfectly.

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

    
asked by anonymous 07.07.2015 / 21:21

1 answer

1

In order to access from anywhere, you would have to have 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. Make sure this environment variable contains C:\Program Files\nodejs\npm\node_modules , otherwise include this value in the list.

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

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

    Your case really seems to be (2).

        
    07.07.2015 / 21:33