Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

javascript - npm在哪里安装软件包?(Where does npm install packages?)

有人可以告诉我在哪里可以找到使用npm安装的Node.js模块吗?

  ask by Tronic translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Global libraries (全球图书馆)

You can run npm list -g to see which global libraries are installed and where they're located. (您可以运行npm list -g来查看安装了哪些全局库以及它们的位置。) Use npm list -g | head -1 (使用npm list -g | head -1) npm list -g | head -1 for truncated output showing just the path. (npm list -g | head -1表示截断的输出,仅显示路径。) If you want to display only main packages not its sub-packages which installs along with it - you can use - npm list --depth=0 which will show all packages and for getting only globally installed packages, just add -g ie npm list -g --depth=0 . (如果只想显示主软件包,而不显示与其一起安装的子软件包,则可以使用npm list --depth=0 ,它将显示所有软件包,并且仅获取全局安装的软件包,只需添加-g即npm list -g --depth=0 。)

On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. (在Unix系统上,全局安装时,它们通常位于/usr/local/lib/node/usr/local/lib/node_modules 。) If you set the NODE_PATH environment variable to this path, the modules can be found by node. (如果将NODE_PATH环境变量设置为此路径,则可以按节点找到模块。)

Windows XP - %USERPROFILE%\AppData\npm\node_modules (Windows %USERPROFILE%\AppData\npm\node_modules)
Windows 7, 8 and 10 - %USERPROFILE%\AppData\Roaming\npm\node_modules (Windows 7、8和10- %USERPROFILE%\AppData\Roaming\npm\node_modules)

Non-global libraries (非全局库)

Non-global libraries are installed the node_modules sub folder in the folder you are currently in. (非全局库安装在您当前所在的文件夹中的node_modules子文件夹中。)

You can run npm list to see the installed non-global libraries for your current location. (您可以运行npm list来查看当前位置已安装的非全局库。)

When installing use -g option to install globally (安装时,使用-g选项进行全局安装)

npm install -g pm2 - pm2 will be installed globally. (npm install -g pm2 -pm2将被全局安装。) It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.) (然后通常可以在/usr/local/lib/node_modules (使用npm root -g检查位置。))

npm install pm2 - pm2 will be installed locally. (npm install pm2 -pm2将在本地安装。) It will then typically be found in the local directory in /node_modules (然后通常会在/node_modules的本地目录中找到它)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...