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 npm Basics (retiring) Installing Packages with npm Installing Global Packages

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

http-server not working..

Hi

I have installed NPM globally (and locally into a directory for this class) onto my computer via the console (I'm on a MAC OSX 10). I have also managed to install an http-server folder in my node_modules folder. When I attempt to run the http-server in the console with a file path that leads to a folder (in this case it's a test.js file inside of the http-server folder...I also attempted to open a package.json file in the same folder/file path as well) the console returns not one, but two url addresses for me to try. I have tried them both in Firefox and in Safari and I get an error on both even though the console tells me that the server is running.

I'm really lost on this one....lol....

Thanks to anyone who can help:-)

Karl Taylor
Karl Taylor
4,043 Points

I'm trying to figure out your problem but I'm a little confused! What's your directory structure?

mySite
|   |---node_modules
|---http-server
|       |---test.js
|       |---package.json

Is this correct? Just a bit confused what you're trying to load on the server!

Also during writing this I think I figured something out. You've installed http-server globally and locally. So it's basically running them both at the same time perhaps?

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Hi Karl,

These are the two different file paths that I tried with the http-server that I had installed globally:

/users/juliettetworsey/node_modules/http-server/package.json

/users/juliettetworsey/node_modules/http-server/test/http-server-test

Thanks!

5 Answers

Have you tried setting a custom port number? ie http-server -p 1337 and http://localhost:1337 ? I usually find this to be more reliable for me than the default port.

also make sure you aren't accidently hitting cntrl + c and shutting down the server- i've done that before.

glad to hear it :)

Michael Hall
PLUS
Michael Hall
Courses Plus Student 30,909 Points

I'm have trouble with this too. I'm using Chrome. my file structure is like this:

node_app - node_modules app.js index.html

I tried running http-server node_app within the node_app folder and I get:

$ http-server node_app -p 3000 Starting up http-server, serving node_app Available on: http:127.0.0.1:3000 http:192.168.0.5:3000 Hit CTRL-C to stop the server [Tue, 17 Nov 2015 16:54:51 GMT] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36" [Tue, 17 Nov 2015 16:54:51 GMT] "GET /" Error (404): "Not found"

when I run it from one directory upp projects/node_app I get no error, but in the browser it says "This Webpage is not available"

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Are you using Workspaces or are you going direct from your own terminal on your computer?

On a couple of occasions I have found that following along on my own terminal (along with my own text editor) did the trick.

Michael Hall
PLUS
Michael Hall
Courses Plus Student 30,909 Points

I'm working on my computer. My html file is just a basic setup. It requires the app.js file and has an h1 tag. Would this make a difference?

Michael Hall
PLUS
Michael Hall
Courses Plus Student 30,909 Points

I did. Thanks for your help, I'm sure it's something silly, I'm going to move on with the course. I'll get it eventually