- Node.js Web Development
- David Herron
- 189字
- 2021-06-25 21:54:07
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.
- Getting Started with Citrix XenApp? 7.6
- 少兒人工智能趣味入門:Scratch 3.0動(dòng)畫與游戲編程
- Java完全自學(xué)教程
- 碼上行動(dòng):零基礎(chǔ)學(xué)會(huì)Python編程(ChatGPT版)
- Banana Pi Cookbook
- C語言程序設(shè)計(jì)同步訓(xùn)練與上機(jī)指導(dǎo)(第三版)
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- SQL經(jīng)典實(shí)例(第2版)
- LabVIEW虛擬儀器入門與測(cè)控應(yīng)用100例
- Domain-Driven Design in PHP
- Learning Python Data Visualization
- ASP.NET Web API Security Essentials
- Python Digital Forensics Cookbook
- Python預(yù)測(cè)之美:數(shù)據(jù)分析與算法實(shí)戰(zhàn)(雙色)
- Java程序設(shè)計(jì)教程