node.js 在 NPM 中安装后找不到 Http-Server 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31694646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:10:29  来源:igfitidea点击:

Http-Server Command Not Found After Install in NPM

node.jsnpmhttpserver

提问by Kamuran S?necek

i installed http-server with npm globally but still I get "command not found"

我在全球范围内使用 npm 安装了 http-server,但仍然出现“找不到命令”

what is wrong

怎么了

my npm command is that

我的 npm 命令是

npm install -g http-server

and http run command

和http运行命令

http-server -p 8000

回答by alioygur

as for me, this problem about the PATH. because the sh can't find the script in specifed PATHS.

至于我,这个关于 PATH 的问题。因为 sh 在指定的 PATHS 中找不到脚本。

you should add the npm global script path to your PATH variable.

您应该将 npm 全局脚本路径添加到您的 PATH 变量中。

if you are using "Git Bash", run the below command.

如果您使用的是“Git Bash”,请运行以下命令。

PATH=$PATH:/c/Users/CHANGE_WITH_YOUR_USERNAME/AppData/Roaming/npm

notice that, this is temporary. when you close the git bash, the PATH variable will be deleted.

请注意,这是暂时的。当您关闭 git bash 时,PATH 变量将被删除。

for the permanently, you have to create a .bashrc file in your home folder.

对于永久,您必须在您的主文件夹中创建一个 .bashrc 文件。

run these commands on your git bash.

在你的 git bash 上运行这些命令。

cd ~
echo PATH=$PATH:/c/Users/CHANGE_WITH_YOUR_USERNAME/AppData/Roaming/npm >> .bashrc

回答by Samrat Saha

@alioygur : Is Exactly Right about the solution.

@alioygur :解决方案完全正确。

But a simple the issue is the installed npm plugin path is not added in the SYSTEM ENVIRONMENT VARIABLE PATH. you had to do that manually.

但一个简单的问题是已安装的 npm 插件路径未添加到SYSTEM ENVIRONMENT VARIABLE PATH 中。您必须手动执行此操作。

now the question comes what is the path address to put in?

现在问题来了,要输入的路径地址是什么?

ANSWER : The path of the installed npm plugin generally goes inside the nodejs installation folder >> nodejs\node_modules\npm\bin

解答:安装的npm插件的路径一般在nodejs安装文件夹内>> nodejs\node_modules\npm\bin

OR

或者

Sometimes npm plugin also resides inside the temporary APP DATA.(As said by @alioygur)

有时 npm 插件也驻留在临时 APP DATA 中。(如@alioygur 所说)

C:\Users\*USERNAME*\AppData\Roaming\npm

QUESTION : How to add path to the SYSTEM ENVIRONMENTmanually without complexity.

问题:如何在不复杂的情况下手动添加到系统环境的路径。

ANSWER : http://www.computerhope.com/issues/ch000549.htm

答案:http: //www.computerhope.com/issues/ch000549.htm

回答by Jigar Bhatt

Enter the following command in your console

在控制台中输入以下命令

sudo npm install http-server -g

回答by Sankalp

Close all cmd and open the cmd and start http-server

关闭所有 cmd 并打开 cmd 并启动 http-server

回答by LINOJ

Try this http-server / 8000if you dont have any specified path

如果你没有任何指定的路径,试试这个http-server / 8000

or your problem may be

或者你的问题可能是

Port 8000 is the default Remote Method Invocation (RMI) Registry port used by the Diagnostic Service.Try Using other port .

端口 8000 是诊断服务使用的默认远程方法调用 (RMI) 注册表端口。尝试使用其他端口。