Global npm install location on windows? - node.js

I'm not 100% sure, but I believe I installed node v5 from the windows installer on both my home and office PCs.
On my home PC global installs happen under %APPDATA%:
(dev) go|c:\srv> which lessc
c:\users\bjorn\appdata\roaming\npm\lessc
c:\users\bjorn\appdata\roaming\npm\lessc.cmd
while on my office PC, they go under program files:
(dev) go|w:\srv> which lessc
c:\program files\nodejs\lessc
c:\program files\nodejs\lessc.cmd
I need to provide the full path to a number of these global tools to PyCharm's file watcher, and since the project file i shared it would make sense to not have global resources under a user folder.
Why would the global installs end up in different folders, and how can I force them to a location that is common to all team members?

According to: https://docs.npmjs.com/files/folders
Local install (default): puts stuff in ./node_modules of the current package root.
Global install (with -g): puts stuff in /usr/local or wherever node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line. -> If you need both, then install it in both places, or use npm link.
prefix Configuration
The prefix config defaults to the location where node is installed. On
most systems, this is /usr/local. On windows, this is the exact
location of the node.exe binary.
The docs might be a little outdated, but they explain why global installs can end up in different directories:
(dev) go|c:\srv> npm config ls -l | grep prefix
; prefix = "C:\\Program Files\\nodejs" (overridden)
prefix = "C:\\Users\\bjorn\\AppData\\Roaming\\npm"
Based on the other answers, it may seem like the override is now the default location on Windows, and that I may have installed my office version prior to this override being implemented.
This also suggests a solution for getting all team members to have globals stored in the same absolute path relative to their PC, i.e. (run as Administrator):
(Run this in cmd, not in PowerShell!)
mkdir %PROGRAMDATA%\npm
setx PATH "%PROGRAMDATA%\npm;%PATH%" /M
npm config set prefix %PROGRAMDATA%\npm
open a new cmd.exe window and reinstall all global packages.
Explanation (by lineno.):
Create a folder in a sensible location to hold the globals (Microsoft is
adamant that you shouldn't write to ProgramFiles, so %PROGRAMDATA% seems
like the next logical place.
The directory needs to be on the path, so use setx .. /M to set the
system path (under HKEY_LOCAL_MACHINE). This is what requires you to run
this in a shell with administrator permissions.
Tell npm to use this new path. (Note: folder isn't visible in %PATH% in
this shell, so you must open a new window).

These are typical npm paths if you install a package globally:
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Newer Windows Versions - %AppData%\npm\node_modules
or - %AppData%\roaming\npm\node_modules

Just press windows button and type %APPDATA% and type enter.
Above is the location where you can find \npm\node_modules folder. This is where global modules sit in your system.

As of today, global packages installed like for eg. npm i -g #vue/cli are by default store in a directory:
C:\Users\<YourUserName>\AppData\Roaming\npm\node_modules

If you're just trying to find out where npm is installing your global module (the title of this thread), look at the output when running npm install -g sample_module
$ npm install -g sample_module C:\Users\user\AppData\Roaming\npm\sample_module ->
C:\Users\user\AppData\Roaming\npm\node_modules\sample_module\bin\sample_module.js
+ sample_module#5.1.0 updated 1 package in 2.821s

here is how I install react globally on windows,
npm install -g react
and I can see package installed at,
C:\Users\username\AppData\Roaming\npm\node_modules

I install node v14.9.0 using nvm and I find it in the D drive: D:\Users\<user_name>\AppData\Roaming\nvm\v14.9.0\node64.exe.

Related

Installed node/npm on macOS Sierra into /usr/local/bin, not executable

Fresh install of macOS Sierra on a new MBP, /usr/local/bin requires root to access the files. But many programs, including node and npm install their executables to /usr/local/bin. I can't execute them unless I'm root. Am I supposed to change permissions on /usr/local/bin in macOS Sierra? Seems there's a reason for the stricter permissions.. Are tools like node/npm just not up to date with how things are done in the latest mac OS and I should move those files to somewhere else like /usr/bin?
Change npm's default directory to another directory that requires you not to run it as root
mkdir ~/my/path
npm config set prefix '~/my/path'
Open or create a ~/.profile file and add this line:
export PATH=~/my/path/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.

'gulp' is not recognized as an internal or external command

I am trying to use Gulp and Node.Js to stream my process for minifying and concatenating CSS/JS files for production.
Here is what I have done.
I installed Node.Js on my Windows 7 machine.
Installed Gulp globally using this command npm install -g gulp
Then I added a new User variable called NODE_PATH set it to %AppData%\npm\node_modules
After closing and re-opening my command line, I tried to run a gulp task from the command line (i.e. gulp css). But that give me the following error
'gulp' is not recognized as an internal or external command
How can I get this to work?
When I opened the following path using the search bar in windows,
%AppData%\npm\node_modules I see the following two folders
gulp
gulp-cli
I've tried to add %AppData%\npm\node_modules to the Path variable on my system variable, but it did not take it because that variable reached it's max allowed character limit.
I removed couple of paths from my Path variable and added ;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
but still not working.
I even tried to set the path at run time using this command
PATH=%PATH%;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
then run gulp and still the same issues.
What am I missing here? What else do I need in order to get this to work?
I had similar issue when I installed locally initially(w/o -g). I reinstalled with -g (global) and then it worked.
npm install -g gulp
you should run gulp from folder where gulpfile.js is available.
I solved the problem by uninstalling NodeJs and gulp then re-installing both again.
To install gulp globally I executed the following command
npm install -g gulp
Go to My Computer>Properties>Advance System Settings>Environment Variables>
Under the variables of Administrator edit the PATH variable & change its value to "C:\Users\Username\AppData\Roaming\npm". Note: The username in the path will be the current Admin user's name that you have logged in with.
I had the same problem on windows 7. You must edit your path system variable manually.
Go to START -> edit the system environment variables -> Environment variables -> in system part find variables "Path" -> edit -> add new path after ";" to your file gulp.cmd directory some like ';C:\Users\YOURUSERNAME\AppData\Roaming\npm' -> click ok and close these windows -> restart your CLI -> enjoy
You may need to install the gulp-cli globally. Uninstall then re-install if you already have it:
npm uninstall -g gulp-cli
npm install -g gulp-cli
Sorry that was a typo. You can either add node_modules to the end of your user's global path variable, or maybe check the permissions associated with that folder (node _modules). The error doesn't seem like the last case, but I've encountered problems similar to yours. I find the first solution enough for most cases. Just go to environment variables and add the path to node_modules to the last part of your user's path variable. Note I'm saying user and not system.
Just add a semicolon to the end of the variable declaration and add the static path to your node_module folder. ( Ex c:\path\to\node_module)
Alternatively you could:
In your CMD
PATH=%PATH%;C:\\path\to\node_module
EDIT
The last solution will work as long as you don't close your CMD. So, use the first solution for a permanent change.
In my case, this problem occured because I did npm install with another system user in my project folder before. Gulp was already installed globally. After deleting folder /node_modules/ in my project, and running npm install with the current user, it worked.
You need to make sure, when you run command (install npm -g gulp), it will create install gulp on C:\ directory.
that directory should match with whatver npm path variable set in your java path.
just run path from command prompt, and verify this. if not, change your java class path variable wherever you gulp is instaled.
It should work.
If you have mysql install in your windows 10 try uninstall every myqsl app from your computer. Its work for me. exactly when i installed the mysql in my computer gulp command and some other commands stop working and then i have tried everything but not nothing worked for me.
I just encountered this on Windows 10 and the latest NodeJS (14.15.1). In my case our admins have our profiles and true "home" folder remotely mount onto our work machine(s). Npm wanted to put its cache over on the remote server and that has worked until this release.
I was unaware that npm has a .npmrc file available. I added one to my actual machine's C:\Users\my-id folder and it contains:
prefix=C:\Users\my-id\nodejs\npm
cache=c:\Users\my-id\nodejs\npm-cache
I also added these paths to my PATH environment variable.
I went to the APPDATA folder on my work machine and the remote "home" server and deleted all the npm related Roaming folders. I deleted the node_modules folder in my project.
I closed all open windows and reopened them. I brought up a command prompt in my project dir and re inited npm and reinstalled the modules I wanted.
After that everything is rolling along.
Just to add to #Vinod R's answer
Go to My Computer>Properties>Advance System Settings>Environment Variables>
Under the variables of Administrator edit the PATH variable & change its value to "C:\Users\Username\AppData\Roaming\npm". Note: The username in the path will be the current Admin user's name that you have logged in with.
After this, move the path to the top as shown in the image attached.
image for demostration
I was having the same exception with node v12.13.1,
Downgraded node to v10.15.3 and it works fine now.
The best solution, you can manage the multiple node versions using nvm installer. then, install the required node's version using below command
nvm install version
Use below command as a working node with mentioned version alone
nvm use version
now, you can use any version node without uninstalling previous installed node.

How to resolve 'npm should be run outside of the node repl, in your normal shell'

I am new to node.js. I downloaded and install node.js installer from the official site. I have added this installer folder in PATH environment variable and I am able to run programs. But when I try to install some package using npm in node console it shows the error npm should be run outside of the node repl, in your normal shell. I also tried it on a separate console. But it shows command not found though I have added node in the environment variable.
For Windows users, run npm commands from the Command Prompt (cmd.exe), not Node.Js (node.exe). So your "normal shell" is cmd.exe. (I agree this message can be confusing for a Windows, Node newbie.)
By the way, the Node.js Command Prompt is actually just an easy shortcut to cmd.exe.
Below is an example screenshot for installing grunt from cmd.exe:
Do not run the application using node.js icon.
Go to All Programmes->Node.js->Node.js command prompt.
Below is example screen shot.
If you're like me running in a restricted environment without administrative privileges, that means your only way to get node up and running is to grab the executable (node.exe) without using the installer. You also cannot change the path variable which makes it that much more challenging.
Here's what I did (for Windows)
Throw node.exe into its own folder (Downloaded the node.exe stand-alone )
Grab an NPM release zip off of github: https://github.com/npm/npm/releases
Create a folder named: node_modules in the node.exe folder
Extract the NPM zip into the node_modules folder
Make sure the top most folder is named npm (remove any of the versioning on the npm folder name ie: npm-2.12.1 --> npm)
Copy npm.cmd out of the npm/bin folder into the top most folder with node.exe
Open a command prompt to the node.exe directory (shift right-click "Open command window here")
Now you will be able to run your npm installers via:
npm install -g express
Running the installers through npm will now auto install packages where they need to be located (node_modules and the root)
Don't forget you will not be able to set the path variable if you do not have proper permissions. So your best route is to open a command prompt in the node.exe directory (shift right-click "Open command window here")
It's better to use the actual (msi) installer from nodejs.org instead of downloading the node executable only. The installer includes npm and makes it easier to manage your node installation. There is an installer for both 32-bit and 64-bit Windows.
Also a couple of other tidbits:
Installing modules globally doesn't do what you might expect. The only modules you should install globally (the -g flag in npm) are ones that install commands. So to install Express you would just do npm install express and that will install Express to your current working directory. If you were instead looking for the Express project generator (command), you need to do npm install -g express-generator for Express 4.
You can use node anywhere from your command prompt to execute scripts. For example if you have already written a separate script: node foo.js. Or you can open up the REPL (as you've already found out) by just selecting the node.js (start menu) shortcut or by just typing node in a command prompt.
As mscdex said NPM comes with the nodejs msi installed file. I happened to just install the node js installer (standalone). To separately add NPM I followed following step
Download the latest zip file of NPM from here.
Extract it in the same file as that of node js installer.
If you have added the directory containing to node js installer to PATH env variable then now even npm should be a recognized command.
you just open command prompt,
then enter in c:/>('cd../../')
then npm install -g cordova
It's simple. Press the Windows logo on your keyboard. Then, type node.js command prompt in the search bar and run it.
You must get directory right path of program(node.js in program files).
such as
and use "npm install -g phonegap"
Just open Node.js commmand promt as run as administrator

bower command not found windows

I am having huge problems trying to use bower (to install foundation 5) or get anything bower related to work on the command line.
I've installed
ruby 1.9.3
git (with run from command prompt option)
Nodejs
I've successfully ran
npm install -g bower grunt-cli
gem install foundation
and these have ran fine. I've looked in the npm/node_modules directory and I can see bower folder in there.
Every time I type bower either into the cmd, ruby cmd or git bash I get
command not recognized
I've set the git path in the environment variables.
What's annoying is the instruction on the bower site. It states:
npm install -g bower
bower install
Well this doesn't work!
I bumped into this problem after npm install -g bower too. I solved the problem by adding npm's binary folder to my path.
Here are some helpful hints for doing that:
Find the location of your npm global binaries: npm config get prefix. This path may look something like C:\Users\username\AppData\Roaming\npm (or C:\ProgramData\chocolatey\lib\nodejs.commandline.X.XX.XX\tools if you use Chocolatey).
Add the path from step 1 to your Path.
Open the Windows Control Panel, search for environment, then click on either edit environment variables for your account, or Edit the system environment variables`.
Find the variable named Path or PATH, or create one if it doesn't exist.
Paste the path from step 1 here (; delimited).
You may need to restart your command prompt window.
You should now be able to enter bower commands.
in case this helps.
I'm a npm / bower nooB - but what happened in my case was, that I was using the Angular JS tutorial,
which seems to have bower set up to be used via npm, and NOT via the command line directly.
Note: in my case I think my bower install got messed up.
I ran this to fix up my bower install:
npm install -gf bower
Then I edited my bower.json file to add in a new library that I wanted to use (in my case angular-sanitize)
I CD to the location of my project
cd myProjectPath
Then to run bower, I actually used npm install:
npm install
This seems to to run bower as a node package, which in turn scans bower.json and installs any missing bower packages.
To run bower as a npm package, add npm before the bower command:
npm bower -v
hope this helps,
Sean
If above solutions don't work. I think you should specify the absolute path to use the bower in command prompt. In my app folder, I just call
C:\Users\yourusername\AppData\Roaming\npm\bower.cmd install
This is content in my bower.cmd. It looks like my windows can't recognize the ~dp0 variable,
node "C:\Users\yourusername\AppData\Roaming\npm\node_modules\bower\bin\bower" %*
This definitly will happen if your Windows PATH variable close to 1024 symbol length. So new links such "C:\Users\username\AppData\Roaming\npm" simply won't fit into that.
Check your PATH, remove extra stuff and try to reinstall node.js and bower etc. Also there is a way to increase 1024-length limit
As others mentioned have to add bower into environment variables, but the easiest way to locate is just simply type in your npm location first, then use Browse File and locate bower on your system(you can search for it in search bar as well), because the location may vary for different users.
1. Type in windows cmd:
for /f %a ('npm config get prefix') do setx path %a
2. Reload cmd
Same issue. I solved it by using another version of bower. It works when i tried to use version 1.2.6
$ npm install -g bower#1.2.6
I had this problem after installing Chocolatey 0.9.8.28. I tried most of the solutions listed here, but I was unable to have 'bower -v' recognized in the Powershell commandline. This seemed a little strange since the Chocolatey Install is 'all about' Powershell. Eventually I was able to succeed by setting the path so that Powershell could find the updated PATH variable settings, but I needed help to understand why and how to do it, which I am providing below:
After failing with Powershell initially, I was able to go to a standard DOS Commandline (not by using cmd /c in powershell) and successfully perform all the variations of path setting that are discussed above and have success in seeing bower and the bower commands recognized by the DOS command line. And the cmd window showed the full updated path (C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.34\tools) - notice that the version number may change from the listing by the honorable KimchiMan.
This PATH persisted through closing and opening new DOS command line windows, but it was not recognized (ever) in any Powershell windows.
Then I discovered the following related discussion: Set Powershell Path Settings.
This points out that Powershell recognizes the HKLM path settings version when starting up. AND it is possible to set the Path EITHER IN the session (non-persistent) or in the Registry (persistent). The following is directly from that discussion.
These commmands can set the PATH temporarily for a powershell SESSION:
$env:Path = 'New path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Process')
These commands can set the PATH permanently for all new Powershell Sessions:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name 'Path' -Value 'New Path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Machine')
But I've messed with setting registry settings programmatically before and I don't believe a line or two of PS script is at all up to the task. So I did not even try this option.
Instead I went to the Control Panel/System console and changed the path through the Environment Variables dialog. I noticed that all the effort I had made to change the path with set PATH in a DOS commandline had worked during the windows session, but the new path entry had not been persisted to the Environment Variables/Registry even though the Dos session was running as administrator.
After I made this change through the Control Panel, the updated path for bower in Chococlatey's tools folder (and presumably all subsequent tool installs) were permanently set and bower was available in both the DOS command line and in the Powershell command line.
hope this helps...
Uninstalled 64bit and Installing 32-bit version of nodejs along with git-
32bit worked!
Had the same issue.
I just ran "npm install -g bower" then visited the directory where it was downloaded, in my case the location was "C:\Users\user\AppData\Roaming\npm\node_modules\bower"
From the directory I ran bower, and everything working fine, even from other directory

Modules are not installing globally with "npm -g install..."

On Ubuntu 12.04 x 64...
npm -g install hiredis redis
Installs fine and npm ls shows those modules, but only when I'm in node source directory
does not show when I'm in any other directory
For kicks, tried running the command while in that other directory- still no dice :(
They are installing globally, but you cannot see them with npm ls, in other directories. Because npm ls only shows local modules. If you want to list global modules you have to type: npm ls -g.
Sometimes another version or just a wrong path is referenced in the npm config file instead of the installed version.
This may cause node/npm to misplace global modules.
To check and fix:
In cmd line type: npm config list
You should get a list of configuration values, one of them is prefix.
Make sure the path in prefix is the same path (only without node.exe) as the actually installed node.exe path.
(this path is listed further down as node bin location)
If it's not, change it:
Either in the config file (in your user folder, named .npmrc)
Or, via cmd line: npm config set prefix "C:\Program Files\nodejs" (change path for ubuntu of course)
Reinstall the module/package you tried to install, don't forget -g for global.

Resources