如何在本地启动http-server [英] How to start http-server locally

查看:387
本文介绍了如何在本地启动http-server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了角度种子,该种子使用节点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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆