1. Home
  2. Node
  3. Adding npm bin/ path to command search path

Adding npm bin/ path to command search path

Overview

npm installs packages by default under node_modules/ within the current working directory. Binary files, if bundled with a package, are installed under node_modules/.bin/ unless the global (-g) flag is supplied to npm install. This works if only a single version of a particular package is installed, but fails in most multi-version setups.

Solution

Add node_modules/.bin/ to your search path, called “PATH". PATH is a special environment variable in bash that defines the order of directories a file is searched for when executing a command.

Simply run this command from the terminal, making note of the single-quote (‘) and double-chevron (>>) usage:

echo 'PATH=$PATH:./node_modules/.bin:../node_modules/.bin' >> ~/.bash_profile

Log out of the terminal and log back in.

Notes: it is acceptable to omit ../node_modules/.bin from the path. This is used for situations like Sails that create a separate directory for its application.

See also

Updated on July 8, 2019

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help! If you get an error, visit https://lithiumhosting.com/support instead.
Contact Support