我对nodejs完全不熟悉。我试图让nodejs在我的Windows 2008盒子上工作,以安装Karma,我将用于TDDing我的AngularJs代码。到目前为止,我已经完成了以下步骤

Install using Chocolatey ==> npm is not recognised Install using 64-bit nodejs installer from nodejs.org ==> npm is not recognised At this stage, running where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing in it I figure out that nodejs is installed in C:\Program Files\nodejs. Opening a command prompt in this directory makes npm work fine. So I added C:\Program Files\nodejs to PATH only to get the same error again that npm is not recognized One of the github issues on nodejs repository says that I need to restart the machine and it would fix. But that has not helped so far I do see a Node.js icon in my Start -> Programms mennu which takes me to nodejs console but not sure what to do with that.

在这个过程中,我是否错过了任何重要的步骤?

Edit

我发现如果我从程序文件中打开“Nodejs命令提示符”,那么npm是可以识别的。如何让它在正常的命令提示符下工作?

Edit

在node之后,我开始在另一个应用程序中遇到类似的问题。我在超级用户上发布了这个问题,正如被接受的答案所正确指出的那样,我在我的PATH中有一个额外的引用,这导致了引用后添加的所有路径出现问题。我有一种感觉,一些Chocolatey安装添加了这句令人不安的引用,但我只是不确定是哪一个。


当前回答

我安装了Node.js,在尝试安装Ionic和cordova时,使用了这段代码:

安装-g cordova ionic

我遇到了上面的错误。我添加了“C:\Program Files\nodejs”到我的环境变量“PATH”。但还是无法克服这个问题。结果发现我的PATH变量超过了2048个字符,所以我无法将Nodejs路径添加到它。我不得不删除另一个程序的路径,并添加Nodejs路径。 关闭并重新打开cmd提示符,并尝试再次安装Ionic。 这对我很管用。

其他回答

我遇到了Ashu描述的同样的问题,但除此之外,nodejs的PATH条目被反斜杠终止:

C:\Program Files\nodejs\

我还必须删除最后的反斜杠,以使它工作。

你只需要把它添加到你的环境变量:

第一步:在搜索栏中写env

或 右键开始按钮->系统->高级系统设置->环境变量…->选择“PATH”

第二步:点击新建按钮,添加如下路径:

C: \ Program Files \ nodejs \

你可能已经收到了回复,但这可能会帮助其他人,因为我最近也遇到了同样的问题,这就是我所做的:

Added a path for Powershell. For me, the path was C:\Windows\System32\WindowsPowerShell\v1.0 Then, I opened the command prompt with administrative privileges and ran @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin Next, choco install nodejs Restart and everything worked fine. Try opening the command prompt without admin privileges and run npm -v

欢呼。

通过命令查看npm config:

npm config list

它需要属性:“prefix”,全局“prefix”和“node bin location”。

; userconfig C:\Users\username\.npmrc
cache = "C:\\ProgramData\\npm-cache"
msvs_version = "2015"
prefix = "C:\\ProgramData\\npm"
python = "C:\\Python27\\"
registry = "http://registry.com/api/npm/npm-packages/"

; globalconfig C:\ProgramData\npm\etc\npmrc
cache = "C:\\ProgramData\\npm-cache"
prefix = "C:\\ProgramData\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\WINDOWS\system32

在这种情况下,它需要将这些路径添加到环境变量PATH的末尾:

;C:\Program Files\nodejs;C:\ProgramData\npm;

将所有提示放在一边,只需在cmd中运行以下一行

> SET PATH=C:\Program Files\Nodejs;%PATH%