http-server command not found
If you do sudo npm install -g
and you don't have an npm
prefix set, the file is probably installed in /usr/local/bin
, but it could be installed more or less anywhere. Whatever directory it's being installed to is probably not in your $PATH
, so you should figure out where it's installed and then update your $PATH
to include it.
I would very strongly recommend you avoid avoid running sudo
with npm. Instead, you can update your prefix
in your npm configuration (or update manually in ~/.npmrc
to something like prefix=~/.npm
but it's up to you. Then you also have to make sure that ~/.npm/bin
is in your path.
Even though global packages can be handy sometimes, if they are tied to particular projects I think it's better to just install it as part of the project and run it there:
cd /path/to/project/with/http-server
npm install http-server
# any of:
npx http-server
node_modules/.bin/http-server
Also if you have a package.json#scripts
, you can reference any locally installed binary as in:
"scripts": {
"server": "http-server"
}
and then use npm run server
.
npm install http-server -g.
please install http-server globally and there after u can run the command
http-server -o
If you are here because you want to test your Angular PWA project locally you need to install http-server package globally using npm install --global http-server
and then only you can run http-server
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