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


当前回答

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

其他回答

有一天,我在自己的Windows 7电脑上遇到了这个问题。问题不在于我的路径,而是我必须使用转义的正斜杠而不是反斜杠,就像这样:

"scripts": {
    "script": ".\\bin\\script.sh"
}

对于Windows用户:一张图片胜过千言万语

参考:npm不能识别为内部或外部命令(注:这是我自己的博客)

为了详细说明布雷诺的回答……对于Windows 7,这些步骤对我来说是有效的:

Open the Control Panel (Click the Start button, then click Control Panel) Click User Accounts Click Change my environment variables Select PATH and click the Edit... button At the end of the Variable value, add ;C:\Program Files\nodejs Click Ok on the "Edit User Variable" window, then click Ok on the "Environment Variables" window Start a command prompt window (Start button, then type cmd into the search and hit enter) At the prompt (C:\>) type npm and hit enter; you should now see some help text (Usage: npm <command> etc.) rather than "npm is not recognized..."

现在你可以开始使用npm了!

我用一个新的答案更新了这个帖子,因为我在不少于一周的时间里找到了解决我痛苦处境的方法……

对于那些仍然遇到错误,即使他们的路径值设置正确,检查你的paextt变量的值(默认值在windows 7 +): .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

我只设置为:. bat,改变它就解决了问题。我想知道为什么没有人提起这件事…

希望这能有所帮助!

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

解决方案:

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