我对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。只需从https://nodejs.org/en/download/releases/下载软件包并在某处提取内容。然后,在命令提示符中,你可以使用cd导航到那里,然后你可以从那个位置运行npm。虽然在运行npm之前必须执行cd C:\Users\YourAcct\Documents\node-v16.13.0 win-x64或类似命令,但这是一种将它放到计算机上并运行npm的方法,而不必成为管理员或编辑环境变量。

其他回答

别忘了以管理员身份运行cmd。

步骤1:安装NodeJs

步骤2:设置环境路径

第三步:重启电脑一次

在64位的Windows 8.1上也有同样的问题。 事实证明,我得到的问题,如果我开始cmd键入在文件夹窗口顶部的路径栏或当我在文件夹窗口中右键单击,然后从列表打开命令提示符。 当我运行cmd使用运行或只是从cmd.exe可执行文件它的工作。

如果你通过服务帐户(如Visual Studio TFS构建控制器服务或任何其他后台服务)得到这个错误,请确保在安装npm后重新启动服务,因为新的PATH环境设置将不会被那些已经运行的进程拾取。我通过我的构建服务得到了同样的错误,但我已经安装了npm并在控制台中运行。

我们只需要安装nodejs,其他什么都不需要做,然后使用命令提示符,将目录切换到你想要安装npm的项目,然后使用npm install命令。这对我很有效。