How to use executables from a package installed locally in node_modules?

前端 未结 22 2129
时光说笑
时光说笑 2020-11-22 12:40

How do I use a local version of a module in node.js. For example, in my app, I installed coffee-script:

npm install coffee-script
22条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:01

    Update: I no longer recommend this method, both for the mentioned security reasons and not the least the newer npm bin command. Original answer below:

    As you have found out, any locally installed binaries are in ./node_modules/.bin. In order to always run binaries in this directory rather than globally available binaries, if present, I suggest you put ./node_modules/.bin first in your path:

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

    If you put this in your ~/.profile, coffee will always be ./node_modules/.bin/coffee if available, otherwise /usr/local/bin/coffee (or whatever prefix you are installing node modules under).

提交回复
热议问题