Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start http-server locally

Tags:

npm

httpserver

I cloned angular seed which is using node http-server and it is working perfectly using following configuration.

Command : npm start (from root of project)

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

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.

like image 831
JS-JMS-WEB Avatar asked Jul 09 '15 21:07

JS-JMS-WEB


People also ask

What is a local HTTP server?

A local web server is a computer that satisfies HTTP requests from the public by returning web pages. For example, a web developer may host a website and have all the files or software necessary for the website physically stored on their computer (locally) as opposed to an external web hosting company.


2 Answers

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.

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).

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

This should have the same effect as running npm start.

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
like image 180
nwinkler Avatar answered Oct 20 '22 01:10

nwinkler


To start server locally paste the below code in package.json and run npm start in command line.

"scripts": { "start": "http-server -c-1 -p 8081" },

like image 25
shubham kapoor Avatar answered Oct 20 '22 03:10

shubham kapoor