Serve a Directory with Node.js

By  on  

As I mentioned in Serve a Directory with Python, sometimes you need a directory to be "served" instead of loading the file:// location within your browser.  In the past I would mess around with MAMPStack and swapping out httpdocs directories, but there are better tools these days.

If you prefer to use Node.js instead of Python, you can use the http-server package:

# Install via shell
npm install http-server -g

# Serve a directory

# Serve a directory at a specified port
http-server -p 2020

Check out the http-server NPM page to check out specific options, but I wanted to highlight how easy it can be to serve a directory with Node.js.  And for JavaScript lovers like me...Node.js is the way to go.

Recent Features

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

  • By
    From Webcam to Animated GIF: the Secret Behind!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

Incredible Demos


    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!