1

I wanted a very simple local http server for testing, and heard about Node.js's http-server module:

http-server

A simple zero-configuration command-line http server http-server is a simple, zero-configuration command-line http server. It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning.

I've installed it with NPM and the instructions from here look wonderfully simple:

Usage:

http-server [path] [options]

After I remembered to wrap my folder directory in double quotes so it wouldn't trip up on spaces in directory names, it appeared to "just work":

enter image description here

...except it defaults to serving up my local content on my public IP address (the one I blanked out in the screenshot) in addition to 127... and 192....

I only want localhost (127...) but I can't see any relevant option in the options in the documentation (it mentions "address" but says the default address is 0.0.0.0).

I must be missing something obvious here. How do I set it to only serve to localhost / 127.0.0.1:8080 and not include the others?

2

It's really easy, it is the -a address option you use. Just add -a 127.0.0.1 after the directory:

http-server "C:\some path\to\some directory\" -a 127.0.0.1

It's in the documentation, but I'd been confused by the reported default value:

-a Address to use (defaults to 0.0.0.0)

Presumably, when it says "defaults to 0.0.0.0", it means something like "defaults to 0.0.0.0 which in turn defaults to some system default" (like the set of three IP addresses above).

2
  • 1
    Listen on 0.0.0.0, on all systems I know, means listen on all available addresses. – user2313067 Sep 10 '16 at 8:09
  • Aha, didn't know that, the docs make sense now – user56reinstatemonica8 Sep 10 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.