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
http-server

# 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
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

  • By
    5 Awesome New Mozilla Technologies You’ve Never Heard Of

    My trip to Mozilla Summit 2013 was incredible.  I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out.  MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

Incredible Demos

Discussion

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