Where does "npm install -g <package>" install the package? [duplicate] - macos

This question already has answers here:
Where does npm install packages?
(23 answers)
Closed 3 years ago.
I have installed some packages using npm install -g and was wondering were they were actually installed?
If I use npm install they are installed in the current directory under node_modules it appears.
I understand how to use the -g flag from (when to use) and (how to use).

When you do npm install -g <package>” then it means you want to install that particular npm module system wide (globally). And when you do without the g option, then module would be installed locally inside the current directory called node_modules.
The -g(global) directive tells npm to install the package in the global shared node_modules folder and usually you get that where nodejs resides(Path: C:\Program Files\nodejs).This will also allow you to access the module from the command-line at global level.
You can also check where global packages/libraries are installed:
Run below command
npm list -g or npm root -g
In windows:
C:\Users\admin>npm list -g
C:\Users\admin\AppData\Roaming\npm\node_modules
In mac: you find node_modules here
/usr/local/lib/node_modules
Whenever you put -g then it installed that file globally and that can accessed in any folder you wants then you don't need to install again again same package.
For more details.
You can also check where local packages/libraries are installed:
run npm list or npm root
And, when you simply install then that particular package restricted to that folder.
So, whenever you package dependencies at global level then you need to put -g while installing folder.So,
If you’re installing something that you want to use in your program,
using require('whatever'), then install it locally, at the root of
your project.
If you’re installing something that you want to use in your shell, on
the command line or something, install it globally, so that its
binaries end up in your PATH environment variable.
check this.
Hope it helps.Thanks

Related

node-sass: command not found after installing globally

I had node sass installed globally on my machine previously then after a reset I had to reinstall.
I have tried installing it globally as I use it to compile .scss files in specific directories. After trying to install it globally and reinstall it globally it does not work. I did this on a separate machine and it works without issues.
Tried the following:
npm i node-sass -g
npm install node-sass
npm install -g node-sass
$ node-sass -v
bash: node-sass: command not found
You can use npx to run node-sass. npx will check if you have a global path to the npm package, and if not, it will temporaily download and execute it.
For instance, to run node-sass and check version.
npx node-sass -v
I tried installing node-sass globally on my linux PC, then running node-sass -v and it worked.
Assuming that you are running your commands on Linux, you might not have your npm home in your $PATH, so your OS doesn't know where to look for when you write node-sass.
To solve this look for your npm home folder (where you have installed node-sass), then add that path to the $PATH environment variable.
You can run npm list -g, and the first output line is the path of your global npm sources (the directory you need is bin, not lib).
You might also want to follow this guide to be able to run npm packages commands as root: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally.
If you do this you should re-install all your global packages in order to have them all in the same directory.
If you are using Windows, is basically the same, only the method of setting the env var changes.

I Installed npm But Cannot Install DocPad

Obviously I need to download DocPad (file(s)) before I can do an npm install, but it simply isn't clear to me what to download, etc. I know the file(s) I need are on GitHub, but I don't have the background to understand what I'm looking at. Can you give me, or point me to, a "Download DocPad for Dummies" instructions? Thank you.
To extend on #sindis's comment
When you install Node, you will also install npm, which serves as the node package manager.
npm allows you to install packages globally using the -g flag, which installs a package that has been published to npm (such as DocPad) to wherever the npm global installation directory is, and make DocPad's command line tools available to you.
So by installing DocPad with npm install -g docpad#6.78 (6.78 is the version of DocPad that the command above wishes to install) we will install DocPad to the global npm installation directory, which makes the command line tool docpad available for your use.
I've updated the DocPad installation guide to be a bit clearer about this, suggestions welcome.
The installation of DocPad is all controlled by NPM. So once that is installed, all you should need to do to install DocPad is run the npm command, as others have said, npm install docpad -g.
Now, the gotcha in windows is that you might need to execute this command with elevated rights - ie Administrator. Windows doesn't like you installing programs in its root program directory.

Chocolatey, npm and grunt-cli installation problems

I am having an issue with the path that my node packages are installing on Windows 8.1. Having installed node using Chocolatey I done the following steps:
Install Chocolatey
choco install npm
npm install -g grunt-cli
So having done the above I open a cmd prompt in admin mode and type 'npm', it works fine from any directory an gives me the usual npm usage stuff. Next I type 'grunt' and I get ''grunt' is not recognized as an internal or external command...'.
So straight away I think this is a PATH problem which it most likely is.
My PATH had nothing to do with npm on it, so I added 'C:\Users\MYNAME\AppData\Roaming\npm' to it, tried 'grunt' again with no luck. I looked inside 'C:\Users\MYNAME\AppData\Roaming\npm\node_modules' and nothing is installed so I ran 'npm install -g grunt-cli' again and noticed
C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\grunt -> C:\ProgramData\chocolatey\lib\nodejs.commandline
.0.10.33\tools\node_modules\grunt-cli\bin\grunt
grunt-cli#0.1.13 C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\node_modules\grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.5)
└── findup-sync#0.1.3 (lodash#2.4.1, glob#3.2.11)
So from looking at this npm is installing everything in 'C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\node_modules' my question is should I just add this to my path and work ahead or is there something I can do to get npm to use the default install location in 'C:\Users\MYNAME\AppData\Roaming\npm' as the npm-cache in 'C:\Users\MYNAME\AppData\Roaming\npm-cache' seems to filling up as expected?
Thanks
NPM might be tool old from that package. It's my understanding they are no longer offering a separate NPM away from NodeJS (I could be incorrect here, I'd love to be wrong).
I'd prefer using the nodejs.install package (which comes with npm).
To answer your question: the location with a package version is not optimal, but I'm not sure that NPM knows a better location as of the version that is out. I don't have a good answer for you on getting NPM to look at the correct install location based on using the NPM package (which is 1.4.9). https://en.wikipedia.org/wiki/Npm_(software)
Thanks for the reply, your exactly right from my understanding. It's a problem with installing npm via chocolatey which is what I was thinking also but you clarified it.
The fix was to delete the chocolatey node_modules folders and npm from chocolatey, tidy up my PATH and then install node.js from the node.js website and npm comes packaged with that, it updated my PATH and everything now works as expected.
Thanks again!

Yeoman can't find generators

I have installed yeoman npm install -g yo
and a controller etc. npm install -g generator-meanjs
I get this error :
You don't seem to have a generator with the name meanjs installed.
You can see available generators with npm search yeoman-generator and then insta
ll them with npm install [name].
To see the 0 registered generators run yo with the --help option.
and running yo in cmd (I'm on windows) also returns 0 generators, only menu to install.
What to do?
You must to re-install your nodejs with the latest version.
add environments variables to path
NODE_PATH = C:\Program Files\nodejs;
npm root= C:\Users\<username>\AppData\Roaming\npm\node_modules;
and it will work .

Grunt installed but not working - "Command not found" on Mavericks

I'm trying to use grunt with sass and have been following these guides:
http://gruntjs.com/getting-started
http://benfrain.com/lightning-fast-sass-compiling-with-libsass-node-sass-and-grunt-sass/
http://www.hongkiat.com/blog/grunt-command-not-found/
I've:
Intsalled node.js
Installed the command-line version of grunt: sudo npm install -g grunt -cli
Added the path from the grunt installer to my bash profile: export PATH=/usr/local/lib/node_modules/grunt/bin:$PATH
Made the profile an executable: source ~/.bash_profile
Setup package.json and Gruntfile.js files in my project root
Installed grunt into the project: cd /path/to/project/root/ and sudo npm install
But when I try to run grunt I see: command not found
It's the same if I run: grunt --version
I wasn't sure if the bash path needs /bin on the end as per the blog posted above but have tried it both ways:
/usr/local/lib/node_modules/grunt/ and /usr/local/lib/node_modules/grunt/bin/
I've also run the grunt installer several times but didn't see any errors so am positive it's installed - can anyone see what I'm doing wrong? I'm running OSX mavericks incase this is the issue.
Any pointers in the right direction would be much appreciated.
Cheers
You have a typo in your command. The package is named grunt-cli without the space.
Update the command to:
sudo npm install -g grunt-cli
And all should work as expected.
Hope this solution also might be helpful to someone. In my case it was a bit trickier.
In command line type the following command
npm install grunt-cli -g
This will show you the location where the grun client is installed:
Copy this location and paste it into a file browser. Was this in my case.
C:\Users\zkhaymed\AppData\Roaming\npm\node_modules\grunt-cli\bin
This will open you the location of a grunt file.
Click on the address line of the location and copy it as a text clicking on the right mouse button.
Now go to the Advanced properties of the system at control panel, and paste this address into a System variables and user variables without deleting the other variables.
I was having a very similar issue, hopefully this helps.
1) You want to check where node and npm are actually installed. If you used a package manager, such as Homebrew or MacPorts, there may be an issue with the location. Just use the downloadable installer from node.js website. Make sure to use the current version, not the long term support (LTS). The installer will install node and npm in /usr/local/bin, which should already be in your PATH. If you already have node/npm installed you can use which node and which npm to see where they are currently located. You should see /usr/local/bin/node and /usr/local/bin/npm, respectively. You will need to update npm after installing with npm update -g npm. This may require sudo.
2) Once node and npm are correctly installed/updated go to the project's root directory (where you have the Gruntfile.js and package.json) and install Grunt using npm install grunt --save-dev. Remember that Grunt After doing so you should see a new folder called node_modules.
3) Make sure to do the previous step before installing the CLI. You can use Grunt's getting started documentation to help guide you the rest of the way. Just be aware that the instructions for installing Grunt are further down the page than installing the CLI, which makes it somewhat confusing. When Grunt and Grunt-CLI are installed run npm install and run grunt in the command line to execute your Gruntfile.js.
You should now be able to see the versions installed. Note that if you are outside of a project's root directory you will not see a version of Grunt but you will see the Grunt-CLI version. This is because the CLI was installed globally (used from any directory/subdirectory) but Grunt is installed on a per-project basis.
Hopefully this helps!
I just ran into this scenario as well. The following worked for me:
Try deleting C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache (if it exists) and reinstalling global npm modules.
Source: https://github.com/nodejs/node/issues/29287
I had to add this to the PATH (on a Mac after brew install node ):
export NPM_HOME=/usr/local/Cellar/node/6.3.1/libexec/npm
The npm install was not effective, no matter what args I passed to it.

Resources