node.js 如何在 node.exe 中使用 npm?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7300132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use npm with node.exe?
提问by TN.
I have downloaded Windows Binary (.exe) of nodejs from the main page.
我已经从主页下载了 nodejs 的 Windows 二进制文件 (.exe) 。
How can I install and use npm(Node package manager)?
如何安装和使用npm(节点包管理器)?
采纳答案by TN.
npmcan be downloaded (without installation) from here:
npm可以从这里下载(无需安装):
回答by Tracker1
The current windows installer from nodejs.orgas of v0.6.11 (2012-02-20) will install NPM along with NodeJS.
从v0.6.11(2012-02-20) 开始,来自nodejs.org的当前 Windows 安装程序将与NodeJS一起安装 NPM。
NOTES:
笔记:
- At this point, the 64-bit version is your best bet
- The install path for 32-bit node is "Program Files (x86)" in 64-bit windows.
- You may also need to add quotes to the path statement in environment variables, this only seems to be in some cases that I've seen.
- In Windows, the globalinstall path is actually in your user's profile directory
%USERPROFILE%\AppData\Roaming\npm%USERPROFILE%\AppData\Roaming\npm-cache- WARNING: If you're doing timed events or other automation as a different user, make sure you run
npm installas that user. Some modules/utilities should be installed globally. - INSTALLER BUGS: You may have to create these directories or add the
...\npmdirectory to your users path yourself.
- 在这一点上,64 位版本是你最好的选择
- 32 位节点的安装路径在 64 位窗口中为“Program Files (x86)”。
- 您可能还需要在环境变量中的路径语句中添加引号,这似乎只是在我见过的某些情况下。
- 在 Windows 中,全局安装路径实际上在您用户的配置文件目录中
%USERPROFILE%\AppData\Roaming\npm%USERPROFILE%\AppData\Roaming\npm-cache- 警告:如果您以其他用户身份执行定时事件或其他自动化,请确保
npm install以该用户身份运行。一些模块/实用程序应该全局安装。 - 安装程序错误:您可能需要自己创建这些目录或将
...\npm目录添加到您的用户路径中。
To change the "global" location for all users to a more appropriate shared global location %ALLUSERSPROFILE%\(npm|npm-cache)(do this as an administrator):
要将所有用户的“全局”位置更改为更合适的共享全局位置%ALLUSERSPROFILE%\(npm|npm-cache)(以管理员身份执行此操作):
- create an
[NODE_INSTALL_PATH]\etc\directory- this is needed before you try
npm config --global ...actions
- this is needed before you try
- create the global (admin) location(s) for npm modules
C:\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 here- set the permissions appropriately
- administrators: modify
- authenticated users: read/execute
- Set global configuration settings (Administrator Command Prompt)
npm config --global set prefix "C:\ProgramData\npm"npm config --global set cache "C:\ProgramData\npm-cache"
- Add
C:\ProgramData\npmto your System's Path environment variable
- 创建
[NODE_INSTALL_PATH]\etc\目录- 在您尝试
npm config --global ...操作之前,这是必需的
- 在您尝试
- 为 npm 模块创建全局(管理)位置
C:\ProgramData\npm-cache- npm 模块将放在此处C:\ProgramData\npm- 全局安装模块的二进制脚本将放在此处C:\ProgramData\npm\node_modules- 全局安装的模块将放在这里- 适当设置权限
- 管理员:修改
- 经过身份验证的用户:读取/执行
- 设置全局配置设置(管理员命令提示符)
npm config --global set prefix "C:\ProgramData\npm"npm config --global set cache "C:\ProgramData\npm-cache"
- 添加
C:\ProgramData\npm到系统的 Path 环境变量
If you want to change your user's "global" location to %LOCALAPPDATA%\(npm|npm-cache)path instead:
如果要将用户的“全局”位置更改为%LOCALAPPDATA%\(npm|npm-cache)路径:
- Create the necessary directories
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 here
- Configure npm
npm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
- Add the new npm path to your environment's
PATH.setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"
- 创建必要的目录
C:\Users\YOURNAME\AppData\Local\npm-cache- npm 模块将放在此处C:\Users\YOURNAME\AppData\Local\npm- 已安装模块的二进制脚本将放在此处C:\Users\YOURNAME\AppData\Local\npm\node_modules- 全局安装的模块将放在这里
- 配置 npm
npm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
- 将新的 npm 路径添加到您环境的
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.
对于初学者,我最常使用的一些 npm 模块如下。
axios- for more complex http posts/gets- isomorphic-fetch- for http(s) post/get requests
- node-mailer- smtp client
- mssql- interface and driver library for querying MS SQL Server (wraps tedious)
axios- 用于更复杂的 http 帖子/获取- isomorphic-fetch- 用于 http(s) post/get 请求
- 节点邮件程序- smtp 客户端
- mssql- 用于查询 MS SQL Server 的接口和驱动程序库(包装繁琐)
More advanced JS options...
更高级的 JS 选项...
- async/await- async functions, supported via babel
- async/await- 异步函数,通过 babel 支持
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 reports- jest- parallel testing, assertions, mocking, coverage reports in one tool
- babel-plugin-rewire- slightly easier for some mocking conditions vs. jest
mocha- 测试框架chai- 断言库,我喜欢 chai.expectsinon- 间谍、存根和垫片sinon-chai- 使用 sinon 的断言工具扩展 chaibabel-istanbul- 报道报告- jest- 一个工具中的并行测试、断言、模拟、覆盖率报告
- babel-plugin-rewire- 对于某些模拟条件与玩笑相比稍微容易一些
Web tooling.
网络工具。
- webpack- module bundler, package node-style modules for browser usage
- babel- convert modern JS (ES2015+) syntax for your deployment environment.
If you build it...
如果你建造它...
回答by Ashish Uttam
When Node.jsis not installed using the msi installer, npmneeds to be setup manually.
当Node.js的使用未安装MSI安装,NPM需要手动地设置。
setting up npm
设置 npm
First, let's say we have the node.exefile located in the folder c:\nodejs. Now to setup npm-
首先,假设我们有位于文件夹中的node.exe文件c:\nodejs。现在设置npm-
- Download the latest npmrelease from GitHub (https://github.com/npm/npm/releases)
- Create folders
c:\nodejs\node_modulesandc:\nodejs\node_modules\npm - Unzip the downloaded zip file in
c:\nodejs\node_modules\npmfolder - Copy npmand npm.cmdfiles from
c:\nodejs\node_modules\npm\bintoc:\nodejsfolder
- 从 GitHub ( https://github.com/npm/npm/releases)下载最新的npm版本
- 创建文件夹
c:\nodejs\node_modules和c:\nodejs\node_modules\npm - 将下载的 zip 文件解压到文件
c:\nodejs\node_modules\npm夹中 - 将npm和npm.cmd文件复制
c:\nodejs\node_modules\npm\bin到c:\nodejs文件夹
In order to test npm, open cmd.exechange working directory to c:\nodejsand type npm --version. You will see the version of npmif it is setup correctly.
为了测试npm,打开cmd.exe更改工作目录c:\nodejs并输入npm --version. 如果设置正确,您将看到npm的版本。
Once setup is done, it can be used to install/uninstall packages locally or globally. For more information on using npmvisit https://docs.npmjs.com/.
设置完成后,它可用于在本地或全局安装/卸载软件包。有关使用npm 的更多信息,请访问https://docs.npmjs.com/。
As the final step you can add node's folder path c:\nodejsto the pathenvironment variable so that you don't have to specify full path when running node.exeand npmat command prompt.
作为最后一步,您可以将节点的文件夹路径添加c:\nodejs到path环境变量中,这样您就不必在运行时node.exe和npm在命令提示符下指定完整路径。
回答by Prashant
I just installed latest version of node (0.6.12) in Windows 7 using msi (node-v0.6.12.msi).
我刚刚使用 msi (node-v0.6.12.msi) 在 Windows 7 中安装了最新版本的节点 (0.6.12)。
npm is already shipped with it, no need to include it separately.
npm 已经随附,无需单独包含。
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
我在运行 npm(npm install mysql)时遇到了权限问题,从我的 nodejs 所在的路径,即 C:\Program Files (x86)\nodejs
Then I followed below steps:
然后我按照以下步骤操作:
1) Added C:\Program Files (x86)\nodejs\npmin environment variables - Path system variable.
1)C:\Program Files (x86)\nodejs\npm在环境变量中添加- 路径系统变量。
2) went back to only C:\in command prompt and gave the command - npm install mysql- and voila! it worked..
2)只C:\在命令提示符下返回并给出命令 - npm install mysql- 瞧!有效..
Hope this helps.
希望这可以帮助。
回答by malte
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!
我正在使用 npm 在 Windows 上运行 node.js。诀窍是简单地使用 cygwin。我遵循了https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows)下的 howto 。但是请确保您使用 nodejs 的 0.4.11 版本,否则 npm 将失败!
回答by rism
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.
我刚刚从这里安装了适用于 Windows 8.1 的 64 位 Node.js v0.12.0 。它大约有 8MB,因为它是一个 MSI,您只需双击即可启动。它将自动设置您的环境路径等。
Then to get the command line it's just [Win-Key]+[S]for search and then enter "node.js" as your search phrase.
然后要获取命令行,它仅[Win-Key]+[S]用于搜索,然后输入“node.js”作为您的搜索词组。
Choose the Node.js Command Promptentry NOT the Node.jsentry.
选择Node.js Command Prompt条目而不是Node.js条目。
Both will given you a command prompt but only the former will actually work. npm is built into that download so then just npm -whateverat prompt.
两者都会给你一个命令提示符,但只有前者才会真正起作用。npm 内置在该下载中,因此只需npm -whatever在提示符处即可。
回答by Christiaan Westerbeek
Use a Windows Package manager like chocolatey. First install chocolatey as indicated on it's homepage. That should be a breeze
使用像 Chocolatey 这样的 Windows 包管理器。首先按照主页上的指示安装巧克力。那应该是轻而易举的
Then, to install Node JS (Install), run the following command from the command line or from PowerShell:
然后,要安装 Node JS(安装),请从命令行或 PowerShell 运行以下命令:
C:> cinst nodejs.install
C:> cinst nodejs.install
回答by luff
Here is a guide by @CTS_AE on how to use NPM with standalone node.exe: https://stackoverflow.com/a/31148216/228508
这是@CTS_AE 关于如何将 NPM 与独立 node.exe 一起使用的指南:https://stackoverflow.com/a/31148216/228508
- Download the node.exe stand-alone from nodejs.org
- Grab an NPM release zip off of github https://github.com/npm/npm/releases
- Create a folder named: node_modules in the same folder as node.exe
- Extract the NPM zip into the node_modules folder
- Rename the extracted npm folder to npm and remove any versioning ie: npm-3.3.4 –> npm.
- Copy npm.cmd out of the /npm/bin/ folder into the root folder with node.exe
- 从 nodejs.org 下载 node.exe 单机版
- 从 github https://github.com/npm/npm/releases 获取NPM 发布 zip
- 在与 node.exe 相同的文件夹中创建一个名为:node_modules 的文件夹
- 将 NPM zip 解压到 node_modules 文件夹中
- 将提取的 npm 文件夹重命名为 npm 并删除任何版本控制,即:npm-3.3.4 –> npm。
- 用 node.exe 将 /npm/bin/ 文件夹中的 npm.cmd 复制到根文件夹中
回答by Sean
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.
我第一次安装了 Node.js,它包含 NPM,可以从 Windows cmd 运行。但是,请确保以管理员身份运行它。右键单击cmd并选择“以管理员身份运行”。这允许我调用 npm 命令。
回答by Bala Venkat
Search all .npmrc file in your system.
搜索系统中的所有 .npmrc 文件。
Please verify that the path you have given is correct. If not please remove the incorrect path.
请验证您提供的路径是否正确。如果不是,请删除不正确的路径。

