[英]How to use npm with node.exe?
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
(节点包管理器)?
The current windows installer from nodejs.org as 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: 笔记:
%USERPROFILE%\\AppData\\Roaming\\npm
%USERPROFILE%\\AppData\\Roaming\\npm-cache
npm install
as that user. npm install
。 Some modules/utilities should be installed globally. ...\\npm
directory to your users path yourself. ...\\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)
(以管理员身份执行此操作):
[NODE_INSTALL_PATH]\\etc\\
directory [NODE_INSTALL_PATH]\\etc\\
目录
npm config --global ...
actions npm config --global ...
actions之前需npm config --global ...
C:\\ProgramData\\npm-cache
- npm modules will go here C:\\ProgramData\\npm-cache
- npm模块将在这里 C:\\ProgramData\\npm
- binary scripts for globally installed modules will go here C:\\ProgramData\\npm
- 全局安装模块的二进制脚本将在这里 C:\\ProgramData\\npm\\node_modules
- globally installed modules will go here 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
to your System's Path environment variable 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)
路径,请执行以下操作:
C:\\Users\\YOURNAME\\AppData\\Local\\npm-cache
- npm modules will go here C:\\Users\\YOURNAME\\AppData\\Local\\npm-cache
- npm模块将转到此处 C:\\Users\\YOURNAME\\AppData\\Local\\npm
- binary scripts for installed modules will go here C:\\Users\\YOURNAME\\AppData\\Local\\npm
- 已安装模块的二进制脚本将在此处 C:\\Users\\YOURNAME\\AppData\\Local\\npm\\node_modules
- globally installed modules will go here C:\\Users\\YOURNAME\\AppData\\Local\\npm\\node_modules
- 全局安装的模块将在此处 npm config set prefix "C:\\Users\\YOURNAME\\AppData\\Local\\npm"
npm config set cache "C:\\Users\\YOURNAME\\AppData\\Local\\npm-cache"
PATH
. 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模块如下。
More advanced JS options... 更高级的JS选项......
For testing, I reach for the following tools... 为了测试,我找到了以下工具......
Web tooling. 网络工具。
If you build it... 如果你建造它......
scripts
directory that's referenced in package.json
scripts via npm. scripts
目录,通过npm在package.json
脚本中引用。 You can use gulp tools inside plain scripts. When Node.js is not installed using the msi installer , npm needs to be setup manually. 如果未使用msi安装程序安装 Node.js,则需要手动设置npm 。
First, let's say we have the node.exe file located in the folder c:\\nodejs
. 首先,假设我们将node.exe文件放在文件夹
c:\\nodejs
。 Now to setup npm - 现在设置npm -
c:\\nodejs\\node_modules
and c:\\nodejs\\node_modules\\npm
c:\\nodejs\\node_modules
和c:\\nodejs\\node_modules\\npm
c:\\nodejs\\node_modules\\npm
folder c:\\nodejs\\node_modules\\npm
文件夹中 c:\\nodejs\\node_modules\\npm\\bin
to c:\\nodejs
folder c:\\nodejs\\node_modules\\npm\\bin
复制到c:\\nodejs
文件夹 In order to test npm , open cmd.exe
change working directory to c:\\nodejs
and type npm --version
. 为了测试npm ,打开
cmd.exe
将工作目录更改为c:\\nodejs
并键入npm --version
。 You will see the version of npm if it is setup correctly. 如果设置正确,您将看到npm的版本。
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/ .
有关使用npm的更多信息,请访问https://docs.npmjs.com/ 。
As the final step you can add node's folder path c:\\nodejs
to the path
environment variable so that you don't have to specify full path when running node.exe
and npm
at command prompt. 作为最后一步,您可以将节点的文件夹路径
c:\\nodejs
到path
环境变量中,这样您就不必在命令提示符下运行node.exe
和npm
时指定完整路径。
npm
can be downloaded (without installation) from here: npm
可以从这里下载(无需安装):
http://nodejs.org/dist/npm/ http://nodejs.org/dist/npm/
https://github.com/npm/npm/releases https://github.com/npm/npm/releases
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, ie C:\\Program Files (x86)\\nodejs 从我的nodejs所在的路径运行npm(npm install mysql)时,我遇到了权限问题,即C:\\ Program Files(x86)\\ nodejs
Then I followed below steps: 然后我按照以下步骤操作:
1) Added C:\\Program Files (x86)\\nodejs\\npm
in 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! 2)在命令提示符下回到只有
C:\\
并给出了命令npm install mysql
- 瞧! it worked.. 有效..
Hope this helps. 希望这可以帮助。
I am running node.js on Windows with npm. 我用npm在Windows上运行node.js. The trick is simply use cygwin.
诀窍就是使用cygwin。 I followed the howto under https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows) .
我按照https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows)下的howto进行了操作。 But make sure that you use version 0.4.11 of nodejs or npm will fail!
但请确保使用版本0.4.11的nodejs或npm将失败!
I've just installed 64 bit Node.js v0.12.0 for Windows 8.1 from here . 我刚刚安装64位的Node.js v0.12.0为Windows 8.1从这里 。 It's about 8MB and since it's an MSI you just double click to launch.
它大约是8MB,因为它是MSI,你只需双击即可启动。 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. 然后获取命令行,只需
[Win-Key]+[S]
进行搜索,然后输入“node.js”作为搜索短语。
Choose the Node.js Command Prompt
entry NOT the Node.js
entry. 选择
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 -whatever
at prompt. npm内置于该下载中,因此只需
npm -whatever
即时。
Use a Windows Package manager like chocolatey. 使用像巧克力这样的Windows程序包管理器。 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: 然后,要安装Node JS(安装),请从命令行或从PowerShell运行以下命令:
C:> cinst nodejs.install C:> cinst nodejs.install
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
I just installed Node.js for the first time and it includes NPM, which can be ran from the Windows cmd. 我刚刚第一次安装了Node.js,它包含NPM,可以从Windows cmd运行。 However, make sure that you run it as an administrator.
但是,请确保以管理员身份运行它。 Right click on cmd and choose "run as administrator".
右键单击cmd并选择“以管理员身份运行”。 This allowed me to call npm commands.
这允许我调用npm命令。
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.
如果没有,请删除不正确的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.