How to start http-server locally

JS-JMS-WEB picture JS-JMS-WEB · Jul 9, 2015 · Viewed 110.3k times · Source

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.

Answer

nwinkler picture nwinkler · Jul 10, 2015

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