Skip to content
Creates a simple node based web server for a directory
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Add mocked route support Dec 12, 2014


servedir is a simple Node web server for offline development and testing: running servedir from a directory will create a quick local web server. servedir is useful for developing scripts that require a standard web environment and can't use the file:// protocol.

The annotated source code is included in the docs/ folder.


Check out a working copy of the source code with Git, or install servedir via npm. The latter will also install servedir into the system's bin path.

$ git clone git://
$ npm install servedir -g


servedir [path] [port]

  • path - The location to serve files and directories from. Defaults to the current working directory.
  • port - The port number. Default to 8000.

If no port is given, it'll try to find the next free port from 8000 upwards.

Mocked router

To create a mock router, create a routes.json file in the current working directory, and servedir will respond with your data.

For example:

  "GET /foo/:id": {
    "id": "{{id}}",
    "title": "Awesome stuff"
  "POST /ok": {
    "success": true
  "POST /fail": {
    "success": true

Now requests to those URLs will respond with JSON for the mocked endpoints.


$ servedir
$ servedir 8001
$ servedir ~/Documents/example
$ servedir ~/Documents/example 8001


You can’t perform that action at this time.