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 sth wrong?
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"
To use on the command line like sails generate foo you will need to install the npm module globally.
npm install -g sails
You could also use the path to the bin in the command if you don't want to install globally:
./node_modules/sails/bin/sails.js generate foo
The official instructions for sails (https://github.com/balderdashy/sails) advises
To install the latest stable release with the command-line tool:
sudo npm -g install sails
This installs globally and adds to a directory like /usr/local/bin that should be in your $PATH.
But to answer the general question regarding the location of the binaries if you install locally, they should be placed in ./node_modules/.bin directory (so run ./node_modules/.bin/sails ...)
You should use the npm bin command to get an absolute path to your current node bin directory.
For example:
➤ lessc
bash: lessc: command not found
➤ npm bin
/home/brice/[...]/node_modules/.bin
➤ export PATH=$(npm bin):$PATH
➤ lessc --version
lessc 1.7.3 (Less Compiler) [JavaScript]
This avoids the problem of relative paths, especially if you're going to be using this in a build system that will invoke the command in subdirectories.