简体   繁体   English

如何使用npm安装软件包?

[英]How do you install packages with npm?

I have never used nodejs before. 我以前从未使用过nodejs。 I just found out about the npm. 我刚刚发现了npm。 If you wanted to install a package using npm, will you have to download the file first? 如果要使用npm安装软件包,是否需要先下载文件? If so, where do you put the file? 如果是这样,您将文件放在哪里? would you place it in the same folder as the npm? 你会把它和npm放在同一个文件夹吗?

I tried to install faye with npm and this is what I got on the npm-debug.log: 我试图用npm安装faye,这是我在npm-debug.log上得到的:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'faye' ]
2 info using npm@2.7.4
3 info using node@v0.12.2
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 silly cache add args [ 'faye', null ]
6 verbose cache add spec faye
7 silly cache add parsed spec { raw: 'faye',
7 silly cache add   scope: null,
7 silly cache add   name: 'faye',
7 silly cache add   rawSpec: '',
7 silly cache add   spec: '*',
7 silly cache add   type: 'range' }
8 verbose addNamed faye@*
9 silly addNamed semver.valid null
10 silly addNamed semver.validRange *
11 silly addNameRange { name: 'faye', range: '*', hasData: false }
12 silly mapToRegistry name faye
13 silly mapToRegistry using default registry
14 silly mapToRegistry registry https://registry.npmjs.org/
15 silly mapToRegistry uri https://registry.npmjs.org/faye
16 verbose addNameRange registry:https://registry.npmjs.org/faye not in flight; fetching
17 verbose request uri https://registry.npmjs.org/faye
18 verbose request no auth needed
19 info attempt registry request try #1 at 7:19:45 PM
20 verbose request id e2cc452cb2788a4b
21 http request GET https://registry.npmjs.org/faye
22 info retry will retry, error on last attempt: Error: connect EACCES
23 info attempt registry request try #2 at 7:19:55 PM
24 http request GET https://registry.npmjs.org/faye
25 info retry will retry, error on last attempt: Error: connect EACCES
26 info attempt registry request try #3 at 7:20:55 PM
27 http request GET https://registry.npmjs.org/faye
28 verbose stack Error: connect EACCES
28 verbose stack     at exports._errnoException (util.js:746:11)
28 verbose stack     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)
29 verbose cwd C:\tito3
30 error Windows_NT 6.1.7601
31 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "faye"
32 error node v0.12.2
33 error npm  v2.7.4
34 error code EACCES
35 error errno EACCES
36 error syscall connect
37 error Error: connect EACCES
37 error     at exports._errnoException (util.js:746:11)
37 error     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)
37 error  { [Error: connect EACCES] code: 'EACCES', errno: 'EACCES', syscall: 'connect' }
38 error Please try running this command again as root/Administrator.
39 verbose exit [ 1, true ]

Npm will download the relevant files for the module for you. Npm将为您下载模块的相关文件。

There are 2 modes of installing node modules using npm, either locally or globally. 有两种使用npm安装节点模块的模式,本地或全局。 Locally (the default) means the modules are downloaded to a node_modules directory at the location you ran the command, so you would normally run this at the root of your app project. 在本地(默认)意味着将模块下载到运行命令的位置的node_modules目录中,因此通常应在应用程序项目的根目录下运行此模块。 Globally (-g option) means it is downloaded to a location so it can be used by anything on your system Ie grunt_cli 全局(-g选项)表示将其下载到某个位置,以便系统上的任何对象均可使用它,例如grunt_cli

The program files directory on windows is protected so you will need to run the command as an administrator, or run npm install from a non protect path such as c:\\myapp Windows上的程序文件目录受保护,因此您将需要以管理员身份运行命令,或从非保护路径(例如c:\\myapp运行npm install

You might want to look at a package.json file, this is a file that allows you to list all your modules that you need for your app. 您可能需要查看package.json文件,该文件可让您列出应用程序所需的所有模块。 Running just npm install in a location that contains a package.json will cause npm to read the file and download all your dependent modules for you. 仅在包含package.json的位置运行npm install会导致npm读取文件并为您下载所有依赖的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM