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


当前回答

如果你使用ms build工具安装node,路径如下:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\NodeJs

其他回答

好吧,在我的情况下,通过Mocha做测试,我尝试了一切,只是意识到我必须在package.json内的测试用例脚本标记周围删除单引号。

我在所有*.test.js文件上运行mocha测试用例,如下所示:

package.json

之前:

 "scripts": {
    "test": "mocha server/**/*.test.js",
    "test-watch": "nodemon --exec 'npm run test'"
  }

After(删除单引号- npm run test):

 "scripts": {
    "test": "mocha server/**/*.test.js",
    "test-watch": "nodemon --exec npm run test"
  }

对我有用,以防别人也被困在这事上。

如果你正在使用VS Code,关闭VS Code,然后重新打开。

我尝试关闭航站楼,然后打开新的航站楼,但它没有工作。

重新启动VS代码工作!

如果一切顺利的话。我建议检查这个PATHEXT . cmd必须添加。

我不知道为什么大多数用户建议;/在命令中。 我通过移除;和/

之前

;C:\Program Files\nodejs\

后的解决方案

C:\Program Files\nodejs

您需要将它们保存到系统PATH变量中

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

C:\Program Files\nodejs\

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