The http-server command does not run after installing it
http-server: command not foundShort answer
http-server is a command-line package, so it must be installed globally or run through npx. If it is installed but not found, npm's global bin folder is missing from your PATH. Run npx http-server, or add the folder printed by npm prefix -g (plus bin on Linux and macOS) to PATH.
Fix it fast
1Find out which cause you have
Check whether npm installed it globally and where npm puts executables.
npm ls -g --depth=0 npm prefix -g2Match what you see, then jump to its fix
What does the error look like?
http-server: command not found
Cause 1 of 3
It was installed locally, not globally
1Check
A plain npm install http-server puts the package in node_modules of the current folder and does not create a command in your shell.
npm ls -g --depth=0 | grep http-server || echo 'not installed globally'2Fix
Install it globally, or skip the install and run it on demand with npx. Serving the current folder needs no other option.
npm install --global http-server
# or, without installing:
npx http-server3Verify
Start it and open http://localhost:8080, the default port.
http-serverConfirmed by github.com
Cause 2 of 3
npm's global bin folder is not on PATH
1Check
Global executables are linked into {prefix}/bin on Unix and straight into the prefix on Windows (%AppData%\npm by default). That folder has to be on PATH.
echo "$PATH"
ls "$(npm prefix -g)/bin"2Fix
Add the folder to PATH in your shell profile, then open a new terminal.
# ~/.profile or ~/.zshrc (Linux and macOS)
export PATH="$(npm prefix -g)/bin:$PATH"3Verify
In a new terminal, ask the shell where the command is.
command -v http-serverConfirmed by docs.npmjs.com
Cause 3 of 3
The global install failed with a permission error
1Check
The default prefix is often a system folder such as /usr/local. npm's own guide recommends a Node version manager to avoid this; the alternative is a prefix in your home folder.
npm prefix -g2Fix
Point the prefix at a folder you own and put its bin on PATH (not for Windows), then install again without sudo.
npm config set prefix ~/.local
echo 'PATH=~/.local/bin:$PATH' >> ~/.profile
source ~/.profile
npm install --global http-server3Verify
Run the command from any folder.
http-server --helpConfirmed by docs.npmjs.com
How do I stop it coming back?
- Use npx for one-off tools you do not need on every project.
- Install Node.js with a version manager so global installs never need sudo.
- After changing PATH, open a new terminal before testing.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
npm install worked but the command is not found
bash: vite: command not found
npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fix