官术网_书友最值得收藏!

Global package installs

In some instances you want to install a module globally, so that it can be used from any directory. For example, the Grunt or Gulp build tools are widely useful, and conceivably you will find it useful if these tools are installed globally. Simply add the -g option:

$ npm install -g grunt-cli  

If you get an error, and you're on a Unix-like system (Linux/Mac), you may need to run this with sudo:

$ sudo npm install -g grunt-cli

A global install is most important for those packages which install executable commands. We'll get into this shortly.

If a local package install lands in node_modules, where does a global package install land?  On a Unix-like system it lands in PREFIX/lib/node_modules, and on Windows it lands in PREFIX/node_modules. In this case PREFIX means the directory where Node.js is installed. You can inspect the location of this directory like so:

$ npm config get prefix
/Users/david/.nvm/versions/node/v8.9.1

The algorithm used by Node.js for the require function automatically searches this directory for packages if the package is not found elsewhere.

Remember that ES6 modules do not support global packages.

主站蜘蛛池模板: 维西| 雷山县| 长汀县| 上高县| 溧水县| 长治市| 神木县| 兰西县| 新津县| 桃园县| 鹤岗市| 观塘区| 虹口区| 卢氏县| 汉寿县| 英超| 大冶市| 贵德县| 湘潭市| 南丹县| 岳普湖县| 馆陶县| 芜湖县| 余江县| 德州市| 驻马店市| 商水县| 河池市| 桂阳县| 凤阳县| 唐海县| 晋州市| 中宁县| 新郑市| 长兴县| 神农架林区| 顺昌县| 克拉玛依市| 富阳市| 图们市| 泰州市|