如何在本地启动http-server [英] How to start http-server locally
问题描述
我克隆了角度种子,该种子使用节点http-server
,并且在以下配置下运行良好.
I cloned angular seed which is using node http-server
and it is working perfectly using following configuration.
命令:npm start(从项目的根目录开始)
Command : npm start (from root of project)
在package.json
文件中进行以下配置:
Following configuration in package.json
file:
"start": "http-server -a localhost -p 8000 -c-1",
Link to file
但是,我无法直接启动此服务器.例如:从项目的根目录开始,这些命令都不起作用:
However I'm unable to start this server directly. eg: from root of the project, none of these commands work:
> angular-seed npm http-server
> angular-seed node http-server
> angular-seed http-server
此(http服务器)在此处(安装它的根目录)不可用吗?有人可以向我解释一下它是如何工作的,以及如何从项目的根源直接使用它.
Shouldn't this(http-server) be available here(root, where it got installed from)? Could someone please explain me how it is working and how I can use it directly from root of the project.
如果在全球范围内安装它,我敢肯定它会正常工作,但是对此我不感兴趣.
I'm sure it will work fine if I install it globally but I'm not interested in that.
推荐答案
在项目根目录中运行npm install
时,它将所有npm依赖项安装到项目的node_modules
目录中.
When you're running npm install
in the project's root, it installs all of the npm dependencies into the project's node_modules
directory.
如果查看项目的node_modules
目录,则应该看到一个名为http-server
的目录,其中包含http-server
软件包,以及一个.bin
文件夹,其中包含来自已安装依赖项的可执行二进制文件. .bin
目录应具有http-server
二进制文件(或指向它的链接).
If you take a look at the project's node_modules
directory, you should see a directory called http-server
, which holds the http-server
package, and a .bin
folder, which holds the executable binaries from the installed dependencies. The .bin
directory should have the http-server
binary (or a link to it).
因此,在您的情况下,应该可以通过从项目的根目录(而不是npm start
)运行以下命令来启动http-server
:
So in your case, you should be able to start the http-server
by running the following from your project's root directory (instead of npm start
):
./node_modules/.bin/http-server -a localhost -p 8000 -c-1
这应该与运行npm start
具有相同的效果.
This should have the same effect as running npm start
.
如果您正在运行Bash shell,则可以通过将./node_modules/.bin
文件夹添加到$PATH
环境变量中来简化此操作:
If you're running a Bash shell, you can simplify this by adding the ./node_modules/.bin
folder to your $PATH
environment variable:
export PATH=./node_modules/.bin:$PATH
这会将这个文件夹放在您的路径上,您应该可以简单地运行
This will put this folder on your path, and you should be able to simply run
http-server -a localhost -p 8000 -c-1
这篇关于如何在本地启动http-server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!