Node Aliases for Globally Installed Packages on Mac

Recently I posted on how globally installed node packages are added to the Windows command prompt. Today I look at the same for Mac.

Unlike on Windows, there is no output for “whereis ng”. Examining the path (“echo $PATH”) provides /usr/local/bin. In this folder are many links, including many for node packages. For example, npm links to “../lib/node_modules/npm/bin/npm-cli.js”.

This is an “executable” script file. In this case JavaScript, which is run by node via the first line of the script “#!/usr/bin/env node”

Thus the full path to the global packages are in /usr/local/lib/node_modules, and the commands are linked from the path /usr/local/bin.

Node Aliases for Globally Installed Packages on Windows

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.


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.

Show Available NPM Package Versions

Since I have been working with node and npm, I find myself updating packages and dealing with package dependencies. It is helpful to see a list of all versions currently published in npm for a given package. Here is the syntax:

npm show <package-name> versions


 > npm show bootstrap-css-only versions
[ '2.3.2-1',
  '4.0.0-beta.2' ]