Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Gulp Basics Welcome to Gulp.js Installing Gulp

Rebekah Shaw
Rebekah Shaw
18,687 Points

-bash: http-server: command not found

I have been trying to to run http-server in my terminal on mac but every time I type it I get the following

-bash: http-server: command not found

I tried to install it with the following command

npm install http-server -g

This didn't fix the problem. I also tried the following command but it also didn't fix the problem.

sudo npm install http-server -g

I am so confused as to what is going on because other questions say that if I install it using sudo then it should work.

5 Answers

Neil McPartlin
Neil McPartlin
14,662 Points

Hi Rebekeh. I did this course a few months back but I use Windows, and not a Mac, but I follow your logic in trying to resolve this. I see this same video has several other community posts from other users encountering the same problem.

1: As suggested in the video, make sure you have NPM and Node installed by typing which node followed by which npm. If successful, you should be shown the location of each installation.

2: Type again sudo npm install http-server -g like you did before, but copy/paste here what is returned to your console. There may be some mention of a problem within the text.

3: Type npm list -g http-server

If your installation had been successful, this command should simply return which version of http-server has been installed globally.

Rebekah Shaw
Rebekah Shaw
18,687 Points

I have both node and npm install and did what you said and I am still having the same problem

Neil McPartlin
Neil McPartlin
14,662 Points

...like you did before, but copy/paste here what is returned to your console. There may be some mention of a problem within the text.

I wasn't offering a solution but I am encouraging you to show us what you actually see when you type in these commands. I'm not a Mac expert but others who are, may be able to suggest the best way forward. I have since tried this on a Mac and it worked first time for me, but I have Googled about this and you are definitely not alone. One popular observation is that there may be a problem with your NPM installation and it is not successfully placing newly installed packages where they can be found in your $PATH. For comparison, here is what i see when i type in some specific commands...

npm -v

5.7.1

npm list -g http-server

/usr/local/lib

└── http-server@0.10.0 

echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

http-server

Starting up http-server, serving ./public
Available on:
  http://127.0.0.1:8080
  http://192.168.100.22:8080
Hit CTRL-C to stop the server

npm list -g npm

/usr/local/lib
└── npm@5.7.1 

As you see with my own installation, both NPM and http-server are located in the /usr/local/lib folder and yet this folder is not listed within my own $PATH, so I cannot explain why mine works.

That said, it will definitely help if you post your responses too so that others can help.

Adam Beer
Adam Beer
11,314 Points

Hi Neil! Thank you so much! Now working my http-server command in git.

Tuan Phan
Tuan Phan
10,825 Points

Hi Neli, I follow your instructions and I got this. Both "npm list -g http-server" and "npm list -g npm" output

--(empty)

Could you tell me what should I do please.

Neil McPartlin
Neil McPartlin
14,662 Points

Hi Steve. As mentioned, I'm primarily a Windows user and maybe I got lucky when I installed node and npm on my Mac some 2 years ago now. So I'm really hoping a knowledgeable Mac user can step in and offer advice. That said, when you tried typing both 'which node' and 'which npm' and these too failed to show signs of an installation, then maybe, just maybe, node is not installed.

I googled 'how to install npm on a mac' and by coincidence, the first match (for me) was a blogpost by one of my favourite teachers on Treehouse, Dave McFarland.

http://blog.teamtreehouse.com/install-node-js-npm-mac

In it, he explains why he recommends Mac users install an app called Brew. Not only can Brew be used to install Node, it can then be used to install Node packages (like http-server etc.). He observes that if you visit this link on a Mac...

https://nodejs.org/en/

...you do get offered a download for a Mac but he describes 3 reasons why using Brew is the better way forward.

Good luck.

Tuan Phan
Tuan Phan
10,825 Points

Hi Neli,

Thank you so much for taking your time for helping me. I am really appriciated.

I will check it out.

Hi, Neil, Windows 7 Pro user:

$ which node
/c/Program Files/nodejs/node

$ which npm
/c/Program Files/nodejs/npm

$ npm list -g http-server
C:\Program Files\Git\usr\local
`-- (empty)

$ env|grep PATH
HOMEPATH=\Users\Millionaire
MANPATH=/mingw64/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man:
PATH=/c/Users/Millionaire/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Millionaire/bin:/c/Program Files/nodejs:/c/Users/Millionaire/AppData/Roaming/npm:/c/Program Files/nodejs/node_modules/npm/bin:/usr/bin/vendor_perl:/usr/bin/core_perl
EXEPATH=C:\Program Files\Git
NODE_PATH=C:\Users\Millionaire\AppData\Roaming\npm\node_modules
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal
INFOPATH=/usr/local/info:/usr/share/info:/usr/info:/share/info:

Any ideas?

OH MY GOD! OH MY GOD! I FINALLY GOT THE RIGHT PATH FOR THE ENVIRONMENT VARIABLE. THANK YOU, NEIL!!!

Routine Poutine
Routine Poutine
26,050 Points

Sudo. As a mac user I forgot that simple command, delaying the lesson by about 20 minutes:

sudo npm install http-server -g

not

npm install http-server -g

TARIQ ALREHILY
TARIQ ALREHILY
14,822 Points

Had same problem, and this sudo npm install http-server -g solved it, thanks.