NPM : how to source ./node_modules/.bin folder?

Kit Ho picture Kit Ho · Aug 3, 2013 · Viewed 14.9k times · Source

I have a problem on npm installation

I have created a project say project A

cd ~/projectA
npm install sails

but sails command is not found after installation.

I know that it is successfully install in ~/projectA/node_modules directory. but the executable cannot be sourced. And i know it is installed ~/projectA/node_modules/.bin

How can I source the .bin automatically whenever I enter into this projectA folder?

Did I did something wrong?

Answer

bmavity picture bmavity · Sep 21, 2013

I can give you an inelegant solution, which is working for me. I just exported my path in my .bashrc file.

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

Edit: It's been a while, but I have changed my strategy to use npm scripts instead. In the above case, setup package.json as follows:

"scripts": {
    "sails": "sails"
}

Which you can then run with

npm run sails

or with arguments

npm run sails -- <args>