http-server command not found

Jordan Forbes picture Jordan Forbes · Oct 20, 2017 · Viewed 32.5k times · Source

I'm trying to run a basic http-server to test out some html files and I keep running into the same error.

I did sudo npm install -g http-server a bunch of times, but each time I try

simple git:(master) http-server

I keep getting this error:

zsh: command not found: http-server

I've tried other variations such as http-server / 8000, I've tried using different command syntax but nothing seems to be working.

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: tiny update I was able to get a server going with python but I'd really like to know why this wasn't working.

edit 2: problem solved thanks!

Answer

zero298 picture zero298 · Oct 20, 2017

You may not have your npm binaries in PATH.

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 is the directory where my npm binaries are installed whenever I run npm -g install whatever.

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.

Another handy thing that I usually do is add all this to my .bashrc or .bashprofile which is in your home directory:

  • On macOS /Users/username/
  • On *nix: /home/username/

.bashrc

NPM_PACKAGES="${HOME}/.npm-packages"
PATH="$NPM_PACKAGES/bin:$PATH"

However, since it looks like you are using zshell, you'll have to use whatever convention they follow for rc files.


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.

Run npm install --save-dev http-server

and put in your package.json:

{
    "scripts": {
        "start": "http-server ."
    }
}

and then run

npm start