node, npm, and $PATH

I recently started playing with Google’s web-starter-kit, intending to build upon its boilerplate for a personal project.

After downloading and extracting the zip, I went to install the dependencies using npm. I’d already had a previous version of node (and by association npm) installed, so as expected, running npm install successfully installed all the dependencies.

However, when I went to run the gulp serve command to compile assets and serve the site locally, my shell couldn’t find the gulp executable.

After a quick search, I realized what exactly running npm install did for me. According to the CLI docs, npm has two methods of installing packages – without any flags, it defaults to installing them locally, i.e. within the node_modules folder. If you actually do want to install it globally, you can add the -g flag.

That’s well and good, but where exactly are the executables? They’re inside the computer.

More specifically, they’re inside the node_modules folder, nested under .bin. You can append that to your $PATH environment variable like so:

export PATH=./node_modules/.bin:$PATH

And of course, you can make that permanent by adding that to your shell’s profile.