My npm globally installed packages don't work - node.js

I installed a cute-files npm package globally (it doesn't matter it could be anything else), I expect when I run:
cute-files
I will see result but now I see cute-files isn't a command.
I should tell you I changed my npm directory because of some permission errors and now my npm directory is:
/home/nima/.npm-g/lib/node_modules
And one more point when I run this command:
echo $NODE_PATH
I see no results and when I set node path with this command:
NODE_PATH="/home/nima/.npm-g/lib/node_modules"
it doesn't fix my problem and after few minutes NODE_PATH again changes to nothing!
I googled very much but I couldn't fix this.

Related

Npm command not found after launch build.sh file

I installed nvm and then installed npm by nvm install npm.
Nvm and npm have been installed to my main directory ~/.nvm and ~/.npm.
And yes, npm command is correct in every directory in the server on the ssh connection in console.
I added also build.sh file where I wrote npm run prod command and added this in post-receive git hook.
BUT! When I send new commits to this server, I see in console note like "npm command not found".
WHY????
After all, on the server everything is okay!
I tried also move ~/.npm to /usr/local/bin/ but it wasn't help. Probably because .npm it is a folder. I don't know...
I solved problem by deleting .nvm and .npm folders and installing npm through sudo apt-get. I guess it automatically have added needs files in needs directories to make npm command globally available.
In spite of I solved the problem by another way, I want to know what I was doing incorrectly in the first approach, cause maybe in the future I need nvm. Can someone experienced in linux explain me what the problem was?
Make sure the absolute path where npm command was installed is listen within your PATH variable, then make sure you export this variable so your build.sh script can see the new value and search for npm binary.
echo $PATH
export PATH="/path/to/my/installation/:$PATH"
echo $PATH
./build.sh

Gulp Not Found Even after Changing Global File Path

I've done all of the recommendations found in other StackOverflow posts about this, but the issue still isn't resolved. I've run the prefix command without it fixing the issue, attempted to remove Gulp and re-install, and run npm install and npm update. Been working on this for hours and no luck. Any help would be much appreciated.
I am running Git Bash with the following folders:
$ npm root -g
C:\Program Files\Git\usr\local\node_modules
$ npm root --dev
C:\Users\HalvorSD\mofficialdev\node_modules
$ npm root -g gulp
C:\Program Files\Git\usr\local\node_modules
Under environment variables in Advanced System Properties, I have:
Variable name: NODE_PATH
Variable value: %AppData%\npm\node_modules

-bash: jspm: command not found

I am trying to npm install JSPM, so that I can run jspm init, for instance.
npm install -g jspm
is unfortunately not enabling the jspm cli.
npm install jspm --save-dev
in project root, isn't doing the trick either.
node -v = v6.2.1
npm -v = 3.9.3
echo $PATH = /usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/git/bin:/usr/local/bin:/usr/local/git/bin:/usr/local/bin
The error
-bash: jspm: command not found
occurs after running jspm init, or jspm.
OS: OS X El Capitan version 10.11.3
Symlink when running an
npm install -g jspm
/Users/user/.npm-packages/bin/jspm -> /Users/user/.npm-packages/lib/node_modules/jspm/jspm.js
/Users/user/.npm-packages/lib
My thanks as always :)
You might need to add it to your environment variables.
In windows add the following line on your path environment variables:
%appdata%\npm
In OS X it might be something like (I am not sure about the exact syntax but it might give you some direction):
~/.bash_profile
export PATH=$PATH:.
I fixed this by running the installation as sudo:
npm install jspm -g
A lot of the other posts had elaborate workarounds involving NVM, editing permissions on bash files, etc. but I'm too busy and just need this to work. 😉
In the end after thinking through the answer here is what I did to solve this problem.
ONE
I searched around and found that my $PATH variable was located here ~/.profile
so running
emacs ~/.profile
I was able to edit path directly from my terminal(Iterm).
TWO
I made sure to remove any duplicate filepaths and to make sure that all default paths went first, so that my local paths would override them. It ended up looking like this
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/sbin:/usr/local/git/bin:/usr/local/mysql/bin:/usr/local/bin
THREE
In addition, I realized that if any path was missing it would be the
/Users/user/.npm-packages/bin
filepath.
I added it, where user would be your name. In my case charlie, so
/Users/charlie/.npm-packages/bin.
That did it, running jspm worked as expected. NOICE!
FINAL $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/sbin:/usr/local/git/bin:/usr/local/mysql/bin:/usr/local/bin:/Users/charlie/.npm-packages/bin

Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)

Running nodejs on Windows 7 Enterprise at work.
Whenever I install a node_module that needs -g access, from experience I know it's supposed to create a *.bat file in %AppData$/Roaming/npm, but for some reason it no longer does that.
For example, I will run npm install gulp -g, console looks like it installed correctly, but the files will not be in the AppData folder. And if I try running a gulp command, I get error sh.exe": gulp: command not found.
If I run the npm install gulp -g command in Console As Administrator, it installs the files into the %AppData% folder of the administrator (instead of the regular user). So if I run the gulp command through my non-administrator user, I still get error sh.exe": gulp: command not found.
Any ideas?
Found solution:
(1) Upon running the command: npm config get prefix, output is C:\Program Files (x86)\Git\local. No idea why it was set to this, as it's not the default.
But I changed it using: npm config set prefix "$APPDATA\npm".
Now when I install a --g module, ie. npm install gulp -g, it installs into this desirable directory, no longer throwing EPERM and ENOENT errors.
(2) Still need to add a PATH entry for the npm folder. The command export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm works temporarily, but if you close console and open it again, might not be saved (if you are not an administrator).
But you can also use echo 'export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm' >> ~/.bash_profile, which will create a .bash_profile file, which is run each time as your console is opened. So from this point, it should automatically add the required PATH entry.
I also faced this same issue.
After installing node.js(https://nodejs.org/en/download/) npm folder(in appdata folder) remain empty.
so, at this stage if you try to build/run angular project(ng build/ng serve), it will give error as:
The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program.
So, for fixing this issue install angular globally in your project with following command:
npm install -g #angular/cli
Now, there would be data in npm folder(node modules etc.) and ng command will run now.

Setting the global NPM folder

So ultimately, I am trying to install gulp by following this tutorial http://travismaynard.com/writing/getting-started-with-gulp, and I was having a lot of problems initially. I kept getting the error that "gulp is not recognized as an internal or external command", which is confusing to me because I found that by running npm ls that gulp had been installed properly. The command wasn't being recognized even after restarting command prompt. I found an article online http://blog.webbb.be/command-not-found-node-npm/ that I may have installed gulp in my local folder other than the global node_module folder. However, when I tried to reset the npm folder with npm config set prefix usr/local/, I received errors. If anyone can walk me through getting the global NPM folder set up and getting the gulp command to work properly, that would be much appreciated.
Try running command prompt as administrator,
or sudo since you seem to be on unix,
you install a package globally by using npm -g,

Resources