找不到HTTP服务器命令 [英] http-server command not found
问题描述
我正在尝试运行基本的http服务器来测试一些html文件,但我一直遇到相同的错误.
I'm trying to run a basic http-server to test out some html files and I keep running into the same error.
我做到了
sudo npm install -g http-server
很多次,但是每次我尝试
I did
sudo npm install -g http-server
a bunch of times, but each time I try
simple git:(master) http-server
我不断收到此错误:
zsh: command not found: http-server
我尝试了其他变体,例如http-server/8000,尝试使用不同的命令语法,但似乎没有任何效果.
I've tried other variations such as http-server / 8000, I've tried using different command syntax but nothing seems to be working.
我的npm版本是5.5.1,我的节点版本是8.3.0,我的操作系统是Mac OSX Sierra v10.12.6
my npm version is 5.5.1, my node version is 8.3.0, and my OS is Mac OSX Sierra v10.12.6
请让我知道您是否可以提供帮助,或者是否发现我做错了什么而我没有注意到.
Please let me know if you can help or if you see anything I'm doing wrong that I'm just not noticing.
edit:微小的更新,我能够使服务器与python一起运行,但是我真的很想知道为什么这不起作用.
edit: tiny update I was able to get a server going with python but I'd really like to know why this wasn't working.
问题解决了,谢谢!
推荐答案
您可能没有PATH
中的npm二进制文件.
You may not have your npm binaries in PATH
.
通过运行echo $PATH
确保您的npm二进制文件在路径中.您应该在打印输出的某处看到类似以下内容的
Make sure that your npm binaries are in path by running echo $PATH
. You should see, somewhere in the printed output, something like:
/home/bob/.npm-packages/bin:/usr/lobal/bin:/other/paths/that/contain/bins
/home/bob/.npm-packages/bin
是每当我运行npm -g install whatever
时安装我的npm二进制文件的目录.
/home/bob/.npm-packages/bin
is the directory where my npm binaries are installed whenever I run npm -g install whatever
.
如果您没有看到类似的内容,请阅读获取npm权限,它将引导您完成环境的正确设置.选项2明确讨论了修复PATH
.
If you don't see something like that, read Fixing npm permissions which will walk you through making sure that your environment is set up correctly. Option 2 explicitly talks about fixing PATH
.
我通常要做的另一件事是将所有这些内容添加到您的主目录中的.bashrc
或.bashprofile
中:
Another handy thing that I usually do is add all this to my .bashrc
or .bashprofile
which is in your home directory:
- 在macOS
/Users/username/
上
- 在* nix上:
/home/username/
- On macOS
/Users/username/
- On *nix:
/home/username/
.bashrc
NPM_PACKAGES="${HOME}/.npm-packages"
PATH="$NPM_PACKAGES/bin:$PATH"
但是,由于看起来您正在使用zshell,因此您必须对rc文件使用遵循的所有约定.
However, since it looks like you are using zshell, you'll have to use whatever convention they follow for rc files.
您可以修复此问题,也可以在项目的程序包级别安装http-server,然后通过npm命令启动它.
You can either fix that or, you can install http-server at a package level for your project and then start it through an npm command.
运行npm install --save-dev http-server
并放入您的package.json:
and put in your package.json:
{
"scripts": {
"start": "http-server ."
}
}
然后运行
npm start
这篇关于找不到HTTP服务器命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!