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

后端 未结 8 1896
慢半拍i
慢半拍i 2021-02-19 14:23

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 fo

8条回答
  •  独厮守ぢ
    2021-02-19 14:53

    In my ~/.bashrc, I have the following:

    function nbin {
      local dir;
      dir=$(npm bin)
      if [ -d "$dir" ]; then
        ( # subshell to not change this shell's $PATH
          PATH=$dir:$PATH
          eval "$@"
        )
      else
        echo "\"$dir\" is not an npm binary directory." >&1
        return 1
      fi
    }
    

    I can then run executable foo in the .bin directory as:

    nbin foo
    

提交回复
热议问题