如何将 npm 与 node.exe 一起使用?
我已经从主页下载了nodejs的Windows二进制文件(.exe)。
如何安装和使用 npm
(Node 包管理器)?
I have downloaded Windows Binary (.exe) of nodejs from the main page.
How can I install and use npm
(Node package manager)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
自 v0.6.11 (2012-02-20) 起,来自 nodejs.org 的当前 Windows 安装程序将与 NodeJS 一起安装 NPM 。
注意:
%USERPROFILE%\AppData\Roaming\npm
%USERPROFILE%\AppData\Roaming\npm-cache
npm install
。一些模块/实用程序应该全局安装。...\npm
目录添加到您的用户路径中。要将所有用户的“全局”位置更改为更合适的共享全局位置
%ALLUSERSPROFILE%\(npm|npm-cache)
(以管理员身份执行此操作):[NODE_INSTALL_PATH ]\etc\
目录npm config --global ...
操作之前需要执行此操作C:\ProgramData\npm-cache
- npm 模块将位于此处C:\ProgramData\npm
- 全局安装模块的二进制脚本将位于此处C:\ProgramData\npm\node_modules
- 全局安装的模块将位于此处npm config --全局设置前缀“C:\ProgramData\npm”
npm config --全局设置缓存“C:\ProgramData\npm-cache”
C:\ProgramData\npm
添加到系统的路径环境变量中如果要将用户的“全局”位置更改为
%LOCALAPPDATA%\(npm|npm-cache)
, 路径改为:C:\Users\YOURNAME\AppData\Local\npm-cache
- npm 模块将位于此处C:\Users\YOURNAME\AppData\Local\npm
- 已安装模块的二进制脚本将位于此处C:\Users\YOURNAME\AppData\Local\npm\node_modules
- 全局安装的模块将位于此处npm 配置设置前缀“C:\Users\YOURNAME\AppData\Local\npm”
npm 配置集缓存“C:\Users\YOURNAME\AppData\Local\npm-cache”
PATH
中。setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"
对于初学者来说,我最常使用的一些 npm 模块如下。
axios - 用于更复杂的 http posts/gets更多高级 JS 选项...
支持测试时,我使用以下工具...
mocha - 测试框架sinon - 间谍、存根和垫片sinon-chai - 使用 sinon 的断言工具扩展 chaiWeb 工具相比,某些模拟条件稍微容易一些。
如果你构建它...
package.json
中引用的scripts
目录 脚本 通过 npm。您可以在纯脚本中使用 gulp 工具。The current windows installer from nodejs.org as of v0.6.11 (2012-02-20) will install NPM along with NodeJS.
NOTES:
%USERPROFILE%\AppData\Roaming\npm
%USERPROFILE%\AppData\Roaming\npm-cache
npm install
as that user. Some modules/utilities should be installed globally....\npm
directory to your users path yourself.To change the "global" location for all users to a more appropriate shared global location
%ALLUSERSPROFILE%\(npm|npm-cache)
(do this as an administrator):[NODE_INSTALL_PATH]\etc\
directorynpm config --global ...
actionsC:\ProgramData\npm-cache
- npm modules will go hereC:\ProgramData\npm
- binary scripts for globally installed modules will go hereC:\ProgramData\npm\node_modules
- globally installed modules will go herenpm config --global set prefix "C:\ProgramData\npm"
npm config --global set cache "C:\ProgramData\npm-cache"
C:\ProgramData\npm
to your System's Path environment variableIf you want to change your user's "global" location to
%LOCALAPPDATA%\(npm|npm-cache)
path instead:C:\Users\YOURNAME\AppData\Local\npm-cache
- npm modules will go hereC:\Users\YOURNAME\AppData\Local\npm
- binary scripts for installed modules will go hereC:\Users\YOURNAME\AppData\Local\npm\node_modules
- globally installed modules will go herenpm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"
npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
PATH
.setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"
For beginners, some of the npm modules I've made the most use of are as follows.
axios - for more complex http posts/getsMore advanced JS options...
For testing, I reach for the following tools...
mocha - testing frameworkchai - assertion library, I like chai.expectsinon - spies and stubs and shimssinon-chai - extend chai with sinon's assertion toolsbabel-istanbul - coverage reportsWeb tooling.
If you build it...
scripts
directory that's referenced inpackage.json
scripts via npm. You can use gulp tools inside plain scripts.如果未使用 msi 安装程序安装 Node.js,则需要手动设置 npm。
设置 npm
首先,假设我们的 node.exe 文件位于文件夹
c:\nodejs
中。现在要设置 npm -c:\nodejs\node_modules
和c:\nodejs\node_modules\npm
c:\nodejs\node_modules\npm
文件夹c:\nodejs\node_modules\npm\ 复制 npm 和 npm.cmd 文件bin
到c:\nodejs
文件夹为了测试 npm,打开
cmd.exe
将工作目录更改为c :\nodejs
并输入npm --version
。如果设置正确,您将看到 npm 的版本。安装完成后,它可用于本地或全局安装/卸载软件包。有关使用 npm 的更多信息,请访问 https://docs.npmjs.com/。
最后一步,您可以将节点的文件夹路径
c:\nodejs
添加到path
环境变量中,这样在运行node 时就不必指定完整路径在命令提示符处运行 .exe
和npm
。When Node.js is not installed using the msi installer, npm needs to be setup manually.
setting up npm
First, let's say we have the node.exe file located in the folder
c:\nodejs
. Now to setup npm-c:\nodejs\node_modules
andc:\nodejs\node_modules\npm
c:\nodejs\node_modules\npm
folderc:\nodejs\node_modules\npm\bin
toc:\nodejs
folderIn order to test npm, open
cmd.exe
change working directory toc:\nodejs
and typenpm --version
. You will see the version of npm if it is setup correctly.Once setup is done, it can be used to install/uninstall packages locally or globally. For more information on using npm visit https://docs.npmjs.com/.
As the final step you can add node's folder path
c:\nodejs
to thepath
environment variable so that you don't have to specify full path when runningnode.exe
andnpm
at command prompt.npm
可以从这里下载(无需安装):http://nodejs .org/dist/npm/https://github.com/npm/ npm/发布
npm
can be downloaded (without installation) from here:http://nodejs.org/dist/npm/https://github.com/npm/npm/releases
我刚刚使用 msi (node-v0.6.12.msi) 在 Windows 7 中安装了最新版本的节点 (0.6.12)。
npm 已经附带了,不需要单独包含它。
我在从我的nodejs所在的路径运行npm(npm install mysql)时遇到权限问题,即
C:\Program Files (x86)\nodejs
然后我按照以下步骤操作:
1) 在环境变量 - Path 中添加
C:\Program Files (x86)\nodejs\npm
系统变量。2) 在命令提示符下返回到
C:\
并给出命令 -npm install mysql
- 瞧!它有效..希望这有帮助。
I just installed latest version of node (0.6.12) in Windows 7 using msi (node-v0.6.12.msi).
npm is already shipped with it, no need to include it separately.
I was facing permission issue while running npm (npm install mysql), from the path where my nodejs resided, i.e.
C:\Program Files (x86)\nodejs
Then I followed below steps:
1) Added
C:\Program Files (x86)\nodejs\npm
in environment variables - Path system variable.2) went back to only
C:\
in command prompt and gave the command -npm install mysql
- and voila! it worked..Hope this helps.
我在 Windows 上使用 npm 运行 node.js。
诀窍就是简单地使用 cygwin。我按照 https://github 下的操作方法进行操作.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows) 。但请确保您使用的nodejs版本为0.4.11,否则npm将会失败!
I am running node.js on Windows with npm.
The trick is simply use cygwin. I followed the howto under https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows) . But make sure that you use version 0.4.11 of nodejs or npm will fail!
我刚刚从 此处。
它大约 8MB,并且由于它是 MSI,因此您只需双击即可启动。它将自动设置您的环境路径等。
然后要获取命令行,只需使用
[Win-Key]+[S]
进行搜索,然后输入“node.js”作为搜索短语。选择
Node.js 命令提示符
条目而不是Node.js
条目。两者都会给你一个命令提示符,但只有前者才能真正起作用。 npm 内置于该下载中,因此只需在提示时使用
npm -whatever
即可。I've just installed 64 bit Node.js v0.12.0 for Windows 8.1 from here.
It's about 8MB and since it's an MSI you just double click to launch. It will automatically set up your environment paths etc.
Then to get the command line it's just
[Win-Key]+[S]
for search and then enter "node.js" as your search phrase.Choose the
Node.js Command Prompt
entry NOT theNode.js
entry.Both will given you a command prompt but only the former will actually work. npm is built into that download so then just
npm -whatever
at prompt.使用像 Chocolatey 这样的 Windows 包管理器。首先安装 Chocolatey,如其主页所示。这应该是一件轻而易举的事
然后,要安装 Node JS(安装),请从命令行或 PowerShell 运行以下命令:
C:> cinst nodejs.install
Use a Windows Package manager like chocolatey. First install chocolatey as indicated on it's homepage. That should be a breeze
Then, to install Node JS (Install), run the following command from the command line or from PowerShell:
C:> cinst nodejs.install
以下是 @CTS_AE 提供的关于如何将 NPM 与独立的 node.exe 一起使用的指南:
https://stackoverflow.com/a/31148216/228508
Here is a guide by @CTS_AE on how to use NPM with standalone node.exe:
https://stackoverflow.com/a/31148216/228508
我刚刚第一次安装 Node.js,它包含 NPM,可以从 Windows cmd 运行。但是,请确保您以管理员身份运行它。右键单击cmd并选择“以管理员身份运行”。这允许我调用 npm 命令。
I just installed Node.js for the first time and it includes NPM, which can be ran from the Windows cmd. However, make sure that you run it as an administrator. Right click on cmd and choose "run as administrator". This allowed me to call npm commands.
搜索系统中的所有 .npmrc 文件。
请验证您提供的路径是否正确。如果不是,请删除不正确的路径。
Search all .npmrc file in your system.
Please verify that the path you have given is correct. If not please remove the incorrect path.