我对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安装添加了这句令人不安的引用,但我只是不确定是哪一个。


当前回答

添加:

;C:\Program Files\nodejs\

在“系统属性”的“环境变量”的“用户变量”部分的路径变量的末尾。

之后,重新打开命令提示符并键入

npm

这应该有用。

其他回答

我按照AngularJS教程安装了nodejs。npm命令工作时,我打开一个新的cmd窗口,但不是在当前的。 所以解决办法是关闭并打开一个新的cmd窗口。

添加:

;C:\Program Files\nodejs\

在“系统属性”的“环境变量”的“用户变量”部分的路径变量的末尾。

之后,重新打开命令提示符并键入

npm

这应该有用。

当我试图使用nvm使用另一个版本的node时,出现了这个问题。我从外部安装node,然后尝试使用nvm使用另一个节点版本。这就是为什么npm无法识别的原因。所以,这就是我所做的:

删除node . js 通过NVM方式安装指定版本的节点

NVM 安装 12

使用NVM使用该版本

NVM 安装 12.22.12

如果安装了NVM(节点版本管理器),也会出现此问题。然后我们尝试通过"npm install"命令进行安装。

解决方案:

只需将名为“NVM_SYMLINK”的环境变量更改为“文件夹的路径” 你安装了Node.exe”。 重启你的电脑,你的问题就解决了。

问题出在系统策略上。我已经尝试了以下评论在权力脚跟,然后它开始工作

$> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force 
$> npm install -g npm-windows-upgrade 
$> npm-windows-upgrade

我从下面的链接得到这个想法