I was curious how that after globally installing a node package using npm, I was able to run new commands such as “ng” at the command prompt in Windows. Where did npm download these packages to? How did these new commands get injected into the standard command prompt.
The first place I looked was Google, which didn’t help initially. I also looked at npm documentation, but while it outlined how to install a package globally, it didn’t say how it was installed. I looked also at the path variable, which had what looked like a promising path C:\Program Files\nodejs. But there were no packages installed here.
I also saw many posts of users with npm installation problems on Linux systems. One of these mentioned the use of the whereis command. I then googled “wheris windows” to discover the Windows “where” command.
where ng
“where ng” told me what I was looking for. The global packages install to the AppData Roaming folder for the currently logged in user.
C:\Users\<login>\AppData\Roaming\npm
Batch Files Live!
This folder contains a node_modules folder similar to what you would see in your project folders, but containing only the global packages. It also has Windows batch .cmd files. So it is funny to think that modern web pipelines wouldn’t work on Windows without the use of decades old technology: .cmd batch files.
At least the node package developers don’t need to code these files. They seem to follow a common pattern for each package and are likely generated by npm during the package installation.
Also, the AppData folder mentioned able is in the path as well, so if I had continued looking more closely at the $PATH variable, I would have come across it as well.