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

后端 未结 8 1894
慢半拍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

    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>
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题