Simple file server to serve current directory

For Node, there's http-server:

$ npm install -g http-server
$ http-server Downloads -a localhost -p 8080
Starting up http-server, serving Downloads on port: 8080
Hit CTRL-C to stop the server

Python has:

  • Python 3: python -m http.server --bind 127.0.0.1 8080
  • Python 2: python -m SimpleHTTPServer 8080

Note that Python 2 has no --bind option, so it will allow all connections (not just from localhost).


There is the Perl app App::HTTPThis or I have often used a tiny Mojolicious server to do this. See my blog post from a while back.

Make a file called say server.pl. Put this in it.

#!/usr/bin/env perl

use Mojolicious::Lite;

use Cwd;
app->static->paths->[0] = getcwd;

any '/' => sub {
  shift->render_static('index.html');
};

app->start;

Install Mojolicious: curl get.mojolicio.us | sh and then run morbo server.pl.

Should work, and you can tweak the script if you need to.


python3 -m http.server

or if you don't want to use the default port 8000

python3 -m http.server 3333

or if you want to allow connections from localhost only

python3 -m http.server --bind 127.0.0.1

See the docs.


The equivalent Python 2 commands are

python -m SimpleHTTPServer

python -m SimpleHTTPServer 3333

There is no --bind option.

See the Python 2 docs.