Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000

Python 3.x

$ python -m http.server 8000

Twisted (Python)

$ twistd -n web -p 8000 --path .

Or:

$ python -c 'from twisted.web.server import Site; from twisted.web.static import File; from twisted.internet import reactor; reactor.listenTCP(8000, Site(File("."))); reactor.run()'

Depends on Twisted.

Ruby

$ ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'

Credit: Barking Iguana

Ruby 1.9.2+

$ ruby -run -ehttpd . -p8000

Credit: nobu

adsf (Ruby)

$ gem install adsf   # install dependency
$ adsf -p 8000

Credit: twome

No directory listings.

Sinatra (Ruby)

$ gem install sinatra   # install dependency
$ ruby -rsinatra -e'set :public_folder, "."; set :port, 8000'

No directory listings.

Perl

$ cpan HTTP::Server::Brick   # install dependency
$ perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'

Credit: Anonymous Monk

Plack (Perl)

$ cpan Plack   # install dependency
$ plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000

Credit: miyagawa

Mojolicious (Perl)

$ cpan Mojolicious::Lite   # install dependency
$ perl -MMojolicious::Lite -MCwd -e 'app->static->paths->[0]=getcwd; app->start' daemon -l http://*:8000

No directory listings.

http-server (Node.js)

$ npm install -g http-server   # install dependency
$ http-server -p 8000

Note: This server does funky things with relative paths. For example, if you have a file /tests/index.html, it will load index.html if you go to /test, but will treat relative paths as if they were coming from /.

node-static (Node.js)

$ npm install -g node-static   # install dependency
$ static -p 8000

No directory listings.

PHP (>= 5.4)

$ php -S 127.0.0.1:8000

Credit: /u/prawnsalad and MattLicense

No directory listings.

Erlang

$ erl -s inets -eval 'inets:start(httpd,[{server_name,"NAME"},{document_root, "."},{server_root, "."},{port, 8000},{mime_types,[{"html","text/html"},{"htm","text/html"},{"js","text/javascript"},{"css","text/css"},{"gif","image/gif"},{"jpg","image/jpeg"},{"jpeg","image/jpeg"},{"png","image/png"}]}]).'

Credit: nivertech (with the addition of some basic mime types)

No directory listings.

busybox httpd

$ busybox httpd -f -p 8000

Credit: lvm

webfs

$ webfsd -F -p 8000

Depends on webfs.

IIS Express

C:\> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\MyWeb /port:8000

Depends on IIS Express.

Credit: /u/fjantomen

No directory listings. /path must be an absolute path.

Meta

If you have any suggestions, drop them in the comments below or on the reddit discussion. To get on this list, a solution must:

  1. serve static files using your current directory (or a specified directory) as the server root,
  2. be able to be run with a single, one line command (dependencies are fine if they're a one-time thing),
  3. serve basic file types (html, css, js, images) with proper mime types,
  4. require no configuration (from files or otherwise) beyond the command itself (no framework-specific servers, etc)
  5. must run, or have a mode where it can run, in the foreground (i.e. no daemons)
@MattLicense

This comment has been minimized.

Show comment Hide comment
@MattLicense

MattLicense Jun 6, 2013

For PHP >=5.4 you can run

$ php -S localhost:8000

For PHP >=5.4 you can run

$ php -S localhost:8000
@nivertech

This comment has been minimized.

Show comment Hide comment
@nivertech

nivertech Jun 6, 2013

Erlang:

erl -s inets -eval 'inets:start(httpd,[{server_name,"NAME"},{document_root, "."},{server_root, "."},{port, 8000}]).'

Erlang:

erl -s inets -eval 'inets:start(httpd,[{server_name,"NAME"},{document_root, "."},{server_root, "."},{port, 8000}]).'
@aschmoe

This comment has been minimized.

Show comment Hide comment
@aschmoe

aschmoe Jun 6, 2013

If you ever use Drupal, drush 5+ has

$ drush rs 8080

aschmoe commented Jun 6, 2013

If you ever use Drupal, drush 5+ has

$ drush rs 8080
@twome

This comment has been minimized.

Show comment Hide comment
@twome

twome Jun 6, 2013

Another Ruby:

$ gem install adsf
$ adsf

twome commented Jun 6, 2013

Another Ruby:

$ gem install adsf
$ adsf
@willurd

This comment has been minimized.

Show comment Hide comment
@willurd

willurd Jun 6, 2013

Thanks for the suggestions everyone!

Owner

willurd commented Jun 6, 2013

Thanks for the suggestions everyone!

@lvm

This comment has been minimized.

Show comment Hide comment
@lvm

lvm Jun 7, 2013

busybox edition:

busybox httpd -p $PORT -h $HOME [ -c httpd.conf ]

Note that the config file is not required but optional.

lvm commented Jun 7, 2013

busybox edition:

busybox httpd -p $PORT -h $HOME [ -c httpd.conf ]

Note that the config file is not required but optional.

@willurd

This comment has been minimized.

Show comment Hide comment
@willurd

willurd Jun 7, 2013

@lvm Thanks. That violates requirement #4 though (because it needs an httpd.conf file).

Owner

willurd commented Jun 7, 2013

@lvm Thanks. That violates requirement #4 though (because it needs an httpd.conf file).

@lvm

This comment has been minimized.

Show comment Hide comment
@lvm

lvm Jun 10, 2013

Oh well, let me rephrase it then :)

lvm commented Jun 10, 2013

Oh well, let me rephrase it then :)

@willurd

This comment has been minimized.

Show comment Hide comment
@willurd

willurd Jun 12, 2013

@lvm Added, thanks!

Owner

willurd commented Jun 12, 2013

@lvm Added, thanks!

@Peeja

This comment has been minimized.

Show comment Hide comment
@Peeja

Peeja Jul 3, 2013

This is awesome! One note though, re: http-server:

Note: This server does funky things with relative paths. For example, if you have a file /tests/index.html, it will load index.html if you go to /test, but will treat relative paths as if they were coming from /.

That should be true for any of these. That's just how HTTP/HTML works. If you go to /test/ (note the trailing slash), then relative URLs will be relative to /test/. Relative URLs are always relative to the last slash in the URL.

The server can't control that; resolving relative URLs is the browser's job, and the browser doesn't know that /test is meant to be a directory. What some servers will do for you is redirect to the trailing-slash URL automatically, which other servers listed here may do—I'm not sure.

Peeja commented Jul 3, 2013

This is awesome! One note though, re: http-server:

Note: This server does funky things with relative paths. For example, if you have a file /tests/index.html, it will load index.html if you go to /test, but will treat relative paths as if they were coming from /.

That should be true for any of these. That's just how HTTP/HTML works. If you go to /test/ (note the trailing slash), then relative URLs will be relative to /test/. Relative URLs are always relative to the last slash in the URL.

The server can't control that; resolving relative URLs is the browser's job, and the browser doesn't know that /test is meant to be a directory. What some servers will do for you is redirect to the trailing-slash URL automatically, which other servers listed here may do—I'm not sure.

@nobu

This comment has been minimized.

Show comment Hide comment
@nobu

nobu Jul 3, 2013

Ruby 1.9.2+:

$ ruby -run -ehttpd . -p8000

nobu commented Jul 3, 2013

Ruby 1.9.2+:

$ ruby -run -ehttpd . -p8000
@willurd

This comment has been minimized.

Show comment Hide comment
@willurd

willurd Jul 7, 2013

@nobu Added, thanks!

Owner

willurd commented Jul 7, 2013

@nobu Added, thanks!

@willurd

This comment has been minimized.

Show comment Hide comment
@willurd

willurd Jul 7, 2013

@Peeja Automatic redirection is probably what's happening. Thanks!

Owner

willurd commented Jul 7, 2013

@Peeja Automatic redirection is probably what's happening. Thanks!

@sudodoki

This comment has been minimized.

Show comment Hide comment
@sudodoki

sudodoki Aug 11, 2013

Just in case you can't install with -g flag in Node.js and node is all you got, try
npm install connect && echo "var c = require('connect');c.createServer(c.static(__dirname)).listen(8080);" | node
Note: may get you really weird results + might pollute your folder with node_modules

Just in case you can't install with -g flag in Node.js and node is all you got, try
npm install connect && echo "var c = require('connect');c.createServer(c.static(__dirname)).listen(8080);" | node
Note: may get you really weird results + might pollute your folder with node_modules

@sshtyck

This comment has been minimized.

Show comment Hide comment
@sshtyck

sshtyck Dec 13, 2013

Perl

$ perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 +? "./$1 |" : $1) if /^GET \/(.*) / })'

Thanks to:
http://stackoverflow.com/questions/8058793/single-line-python-webserver

sshtyck commented Dec 13, 2013

Perl

$ perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 +? "./$1 |" : $1) if /^GET \/(.*) / })'

Thanks to:
http://stackoverflow.com/questions/8058793/single-line-python-webserver

@ahmedelgabri

This comment has been minimized.

Show comment Hide comment
@ahmedelgabri

ahmedelgabri Dec 25, 2013

Created a shell function for this https://gist.github.com/ahmedelgabri/8122545 "I only needed Python, Ruby & PHP", maybe someone will find this useful.

Created a shell function for this https://gist.github.com/ahmedelgabri/8122545 "I only needed Python, Ruby & PHP", maybe someone will find this useful.

@inconshreveable

This comment has been minimized.

Show comment Hide comment
@inconshreveable

inconshreveable Feb 5, 2014

I just created srvdir which solves this problem elegantly. It is open source on github and available as a simple binary download with no dependencies for all major operating systems:

srvdir homepage
srvdir code on github

Unlike all of the other solutions, srvdir serves your directory on a public HTTPS URL with an optional password. This means you can securely share the URL with anyone on the internet and are not restricted to just your local network.

It's also ridiculously simple to use. Serve files in the current directory:

./srvdir

Serve files from multiple named directories simultaneously:

./srvdir /usr/lib /var/www/

I just created srvdir which solves this problem elegantly. It is open source on github and available as a simple binary download with no dependencies for all major operating systems:

srvdir homepage
srvdir code on github

Unlike all of the other solutions, srvdir serves your directory on a public HTTPS URL with an optional password. This means you can securely share the URL with anyone on the internet and are not restricted to just your local network.

It's also ridiculously simple to use. Serve files in the current directory:

./srvdir

Serve files from multiple named directories simultaneously:

./srvdir /usr/lib /var/www/
@moserrya

This comment has been minimized.

Show comment Hide comment
@moserrya

moserrya Apr 15, 2014

gem install knod to install dependency
knod -p 8000

Warning! Knod can also write to and delete from the directory you specify.

gem install knod to install dependency
knod -p 8000

Warning! Knod can also write to and delete from the directory you specify.

@gdiggs

This comment has been minimized.

Show comment Hide comment
@gdiggs

gdiggs Apr 16, 2014

Wrote a go version. It's complicated by the fact that you can't interpret go code from the command line without a file (like you can with ruby) so it makes a file that deletes itself upon exiting.

gdiggs commented Apr 16, 2014

Wrote a go version. It's complicated by the fact that you can't interpret go code from the command line without a file (like you can with ruby) so it makes a file that deletes itself upon exiting.

@sesm

This comment has been minimized.

Show comment Hide comment
@sesm

sesm Apr 29, 2014

Clojure (via Leiningen project management tool):

$ lein simpleton 8080

Note: you should install lein-simpleton plugin first by putting [lein-simpleton "1.3.0"] into the :plugins vector of your :user profile. Profiles are configured in ~/.lein/profiles.clj, if you don't have this file yet, you can start with

$ echo "{:user {:plugins [[lein-simpleton \"1.3.0\"]]}}" > ~/.lein/profiles.clj

sesm commented Apr 29, 2014

Clojure (via Leiningen project management tool):

$ lein simpleton 8080

Note: you should install lein-simpleton plugin first by putting [lein-simpleton "1.3.0"] into the :plugins vector of your :user profile. Profiles are configured in ~/.lein/profiles.clj, if you don't have this file yet, you can start with

$ echo "{:user {:plugins [[lein-simpleton \"1.3.0\"]]}}" > ~/.lein/profiles.clj
@fahrinh

This comment has been minimized.

Show comment Hide comment
@fahrinh

fahrinh May 2, 2014

Spark (Go)

$ go get github.com/rif/spark
$ spark -port 8000 .

fahrinh commented May 2, 2014

Spark (Go)

$ go get github.com/rif/spark
$ spark -port 8000 .
@obscuresec

This comment has been minimized.

Show comment Hide comment
@obscuresec

obscuresec May 18, 2014

PowerShell

$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://+:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type","text/plain");$Buf=[Text.Encoding]::UTF8.GetBytes((GC (Join-Path $Pwd ($HC.Request).RawUrl)));$HRes.ContentLength64=$Buf.Length;$HRes.OutputStream.Write($Buf,0,$Buf.Length);$HRes.Close()};$Hso.Stop()

PowerShell from cmd.exe

PowerShell.exe -nop -enc JABIAHMAbwA9AE4AZQB3AC0ATwBiAGoAZQBjAHQAIABOAGUAdAAuAEgAdAB0AHAATABpAHMAdABlAG4AZQByADsAJABIAHMAbwAuAFAAcgBlAGYAaQB4AGUAcwAuAEEAZABkACgAIgBoAHQAdABwADoALwAvACsAOgA4ADAAMAAwAC8AIgApADsAJABIAHMAbwAuAFMAdABhAHIAdAAoACkAOwBXAGgAaQBsAGUAIAAoACQASABzAG8ALgBJAHMATABpAHMAdABlAG4AaQBuAGcAKQB7ACQASABDAD0AJABIAHMAbwAuAEcAZQB0AEMAbwBuAHQAZQB4AHQAKAApADsAJABIAFIAZQBzAD0AJABIAEMALgBSAGUAcwBwAG8AbgBzAGUAOwAkAEgAUgBlAHMALgBIAGUAYQBkAGUAcgBzAC4AQQBkAGQAKAAiAEMAbwBuAHQAZQBuAHQALQBUAHkAcABlACIALAAiAHQAZQB4AHQALwBwAGwAYQBpAG4AIgApADsAJABCAHUAZgA9AFsAVABlAHgAdAAuAEUAbgBjAG8AZABpAG4AZwBdADoAOgBVAFQARgA4AC4ARwBlAHQAQgB5AHQAZQBzACgAKABHAEMAIAAoAEoAbwBpAG4ALQBQAGEAdABoACAAJABQAHcAZAAgACgAJABIAEMALgBSAGUAcQB1AGUAcwB0ACkALgBSAGEAdwBVAHIAbAApACkAKQA7ACQASABSAGUAcwAuAEMAbwBuAHQAZQBuAHQATABlAG4AZwB0AGgANgA0AD0AJABCAHUAZgAuAEwAZQBuAGcAdABoADsAJABIAFIAZQBzAC4ATwB1AHQAcAB1AHQAUwB0AHIAZQBhAG0ALgBXAHIAaQB0AGUAKAAkAEIAdQBmACwAMAAsACQAQgB1AGYALgBMAGUAbgBnAHQAaAApADsAJABIAFIAZQBzAC4AQwBsAG8AcwBlACgAKQB9ADsAJABIAHMAbwAuAFMAdABvAHAAKAApAA==

PowerShell

$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://+:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type","text/plain");$Buf=[Text.Encoding]::UTF8.GetBytes((GC (Join-Path $Pwd ($HC.Request).RawUrl)));$HRes.ContentLength64=$Buf.Length;$HRes.OutputStream.Write($Buf,0,$Buf.Length);$HRes.Close()};$Hso.Stop()

PowerShell from cmd.exe

PowerShell.exe -nop -enc JABIAHMAbwA9AE4AZQB3AC0ATwBiAGoAZQBjAHQAIABOAGUAdAAuAEgAdAB0AHAATABpAHMAdABlAG4AZQByADsAJABIAHMAbwAuAFAAcgBlAGYAaQB4AGUAcwAuAEEAZABkACgAIgBoAHQAdABwADoALwAvACsAOgA4ADAAMAAwAC8AIgApADsAJABIAHMAbwAuAFMAdABhAHIAdAAoACkAOwBXAGgAaQBsAGUAIAAoACQASABzAG8ALgBJAHMATABpAHMAdABlAG4AaQBuAGcAKQB7ACQASABDAD0AJABIAHMAbwAuAEcAZQB0AEMAbwBuAHQAZQB4AHQAKAApADsAJABIAFIAZQBzAD0AJABIAEMALgBSAGUAcwBwAG8AbgBzAGUAOwAkAEgAUgBlAHMALgBIAGUAYQBkAGUAcgBzAC4AQQBkAGQAKAAiAEMAbwBuAHQAZQBuAHQALQBUAHkAcABlACIALAAiAHQAZQB4AHQALwBwAGwAYQBpAG4AIgApADsAJABCAHUAZgA9AFsAVABlAHgAdAAuAEUAbgBjAG8AZABpAG4AZwBdADoAOgBVAFQARgA4AC4ARwBlAHQAQgB5AHQAZQBzACgAKABHAEMAIAAoAEoAbwBpAG4ALQBQAGEAdABoACAAJABQAHcAZAAgACgAJABIAEMALgBSAGUAcQB1AGUAcwB0ACkALgBSAGEAdwBVAHIAbAApACkAKQA7ACQASABSAGUAcwAuAEMAbwBuAHQAZQBuAHQATABlAG4AZwB0AGgANgA0AD0AJABCAHUAZgAuAEwAZQBuAGcAdABoADsAJABIAFIAZQBzAC4ATwB1AHQAcAB1AHQAUwB0AHIAZQBhAG0ALgBXAHIAaQB0AGUAKAAkAEIAdQBmACwAMAAsACQAQgB1AGYALgBMAGUAbgBnAHQAaAApADsAJABIAFIAZQBzAC4AQwBsAG8AcwBlACgAKQB9ADsAJABIAHMAbwAuAFMAdABvAHAAKAApAA==
@karuna

This comment has been minimized.

Show comment Hide comment
@karuna

karuna Jun 12, 2014

Is there any that show directory listing instead of loading index.html?

karuna commented Jun 12, 2014

Is there any that show directory listing instead of loading index.html?

@zhuangya

This comment has been minimized.

Show comment Hide comment
@zhuangya

zhuangya Jun 22, 2014

@somlor

This comment has been minimized.

Show comment Hide comment
@somlor

somlor Jun 22, 2014

$ gem install serve
$ serve

somlor commented Jun 22, 2014

$ gem install serve
$ serve
@mauvm

This comment has been minimized.

Show comment Hide comment
@mauvm

mauvm Jun 22, 2014

$ npm install -g beefy
$ beefy

With build in support for browserify, watchify, and live-reload.

mauvm commented Jun 22, 2014

$ npm install -g beefy
$ beefy

With build in support for browserify, watchify, and live-reload.

@Paxa

This comment has been minimized.

Show comment Hide comment
@Paxa

Paxa Jun 22, 2014

Also for ruby

$ gem install httpit
$ httpit

Paxa commented Jun 22, 2014

Also for ruby

$ gem install httpit
$ httpit
@kidoman

This comment has been minimized.

Show comment Hide comment
@kidoman

kidoman Jun 22, 2014

brew install kidoman/tools/serve

or

go get github.com/kidoman/serve

Provided you have serve under your $PATH somewhere:

serve .

This will serve the current directory at http://localhost:5000/

serve -p 9999 ~/my-awesome-blog

Will serve the contents of the folder ~/my-awesome-blog at http://localhost:9999/

serve -x /my ~/precious

You guessed it, http://localhost:5000/my is now wired up to ~/precious

serve -o ~/sesame

Wires up http://localhost:5000 to ~/sesame and opens the URL in your favorite browser while it is at it.

https://github.com/kidoman/serve

kidoman commented Jun 22, 2014

brew install kidoman/tools/serve

or

go get github.com/kidoman/serve

Provided you have serve under your $PATH somewhere:

serve .

This will serve the current directory at http://localhost:5000/

serve -p 9999 ~/my-awesome-blog

Will serve the contents of the folder ~/my-awesome-blog at http://localhost:9999/

serve -x /my ~/precious

You guessed it, http://localhost:5000/my is now wired up to ~/precious

serve -o ~/sesame

Wires up http://localhost:5000 to ~/sesame and opens the URL in your favorite browser while it is at it.

https://github.com/kidoman/serve

@jarofghosts

This comment has been minimized.

Show comment Hide comment
@jarofghosts

jarofghosts Jun 22, 2014

shameless plug for node: glance
has index file support, directory listing, error pages, etc etc.

npm install -g glance
glance

shameless plug for node: glance
has index file support, directory listing, error pages, etc etc.

npm install -g glance
glance
@speier

This comment has been minimized.

Show comment Hide comment
@speier

speier Jun 22, 2014

Harp, static web server with built-in preprocessing.

$ npm install -g harp
$ harp server

speier commented Jun 22, 2014

Harp, static web server with built-in preprocessing.

$ npm install -g harp
$ harp server
@Val

This comment has been minimized.

Show comment Hide comment
@Val

Val Jun 22, 2014

Rack (ruby)

gem install rack --no-ri --no-rdoc
rackup -b 'use Rack::Static, :index => 'README.html'; run Rack::File.new('.')"

Val commented Jun 22, 2014

Rack (ruby)

gem install rack --no-ri --no-rdoc
rackup -b 'use Rack::Static, :index => 'README.html'; run Rack::File.new('.')"
@mbleigh

This comment has been minimized.

Show comment Hide comment
@mbleigh

mbleigh Jun 22, 2014

Superstatic, static web server with support for pushState, cache control, and more.

npm install -g superstatic
superstatic -p 8000

mbleigh commented Jun 22, 2014

Superstatic, static web server with support for pushState, cache control, and more.

npm install -g superstatic
superstatic -p 8000
@lethalman

This comment has been minimized.

Show comment Hide comment
@lethalman

lethalman Jun 23, 2014

I'd like to request a bash http server using /dev/tcp, anybody has a one-liner for that?

I'd like to request a bash http server using /dev/tcp, anybody has a one-liner for that?

@amitu

This comment has been minimized.

Show comment Hide comment
@amitu

amitu Jun 23, 2014

$ pip install djangothis
$ djangothis

Assumes html files in current folder are django templates, so inheritance etc work. Also files in static folder are served as static files with correct mime types.

views.py named file can contain importd/django views in case you want to grow.

amitu commented Jun 23, 2014

$ pip install djangothis
$ djangothis

Assumes html files in current folder are django templates, so inheritance etc work. Also files in static folder are served as static files with correct mime types.

views.py named file can contain importd/django views in case you want to grow.

@avsm

This comment has been minimized.

Show comment Hide comment
@avsm

avsm Jun 23, 2014

OCaml is

opam install cohttp async
cohttp-server-async

or

opam install cohttp lwt ssl
cohttp-server-lwt

avsm commented Jun 23, 2014

OCaml is

opam install cohttp async
cohttp-server-async

or

opam install cohttp lwt ssl
cohttp-server-lwt
@kingofsevens

This comment has been minimized.

Show comment Hide comment
@kingofsevens

kingofsevens Jun 27, 2014

Livereload

For python with live reload feature..

pip install livereload
livereload                         #serves current dir with port 35729 which livereload extensions use
livereload ~/testing -p 8000       # to serve specific directory from specific port

And you can setup shell commands and such for livereloading..

Livereload

For python with live reload feature..

pip install livereload
livereload                         #serves current dir with port 35729 which livereload extensions use
livereload ~/testing -p 8000       # to serve specific directory from specific port

And you can setup shell commands and such for livereloading..

@ibaaj

This comment has been minimized.

Show comment Hide comment
@ibaaj

ibaaj Aug 19, 2014

Create an alias in your .bashrc

function serve {
  port="${1:-3000}"
  http-server . -p $port
}

Then just run

serve 5000

ibaaj commented Aug 19, 2014

Create an alias in your .bashrc

function serve {
  port="${1:-3000}"
  http-server . -p $port
}

Then just run

serve 5000
@xudafeng

This comment has been minimized.

Show comment Hide comment
@xudafeng

xudafeng Sep 24, 2014

nodejs

$ npm install startserver -g
$ server 8080

nodejs

$ npm install startserver -g
$ server 8080
@mufid

This comment has been minimized.

Show comment Hide comment
@mufid

mufid Oct 6, 2014

This is very handy to stream media in my notebook to my phone. Awesome! Thanks!

mufid commented Oct 6, 2014

This is very handy to stream media in my notebook to my phone. Awesome! Thanks!

@kishaningithub

This comment has been minimized.

Show comment Hide comment
@kishaningithub

kishaningithub Nov 1, 2014

Very coool gist!! Made my day B-)

Very coool gist!! Made my day B-)

@oboxodo

This comment has been minimized.

Show comment Hide comment
@oboxodo

oboxodo Jan 15, 2015

Add serve

$ gem install serve
$ cd my-project
my-project$ serve

oboxodo commented Jan 15, 2015

Add serve

$ gem install serve
$ cd my-project
my-project$ serve
@ailin-nemui

This comment has been minimized.

Show comment Hide comment
@ailin-nemui

ailin-nemui Apr 23, 2015

you can also start HTTPS server which may be important for WSS services, example with Mojo:
perl -Mojo -MCwd -E'app->static->paths->[0]=getcwd; app->start' daemon -l 'https://*:8000' (note the http_s_)

you can also start HTTPS server which may be important for WSS services, example with Mojo:
perl -Mojo -MCwd -E'app->static->paths->[0]=getcwd; app->start' daemon -l 'https://*:8000' (note the http_s_)

@eadz

This comment has been minimized.

Show comment Hide comment
@eadz

eadz May 24, 2015

For any of these, it would be worth making an alias in your shell.

For example for the ruby example and zsh.

alias server="ruby -run -ehttpd . -p 8080"

in your .zshrc means you can just run "server"

eadz commented May 24, 2015

For any of these, it would be worth making an alias in your shell.

For example for the ruby example and zsh.

alias server="ruby -run -ehttpd . -p 8080"

in your .zshrc means you can just run "server"

@reider-roque

This comment has been minimized.

Show comment Hide comment
@reider-roque

reider-roque Jun 17, 2015

Perl

perl -MHTTP::Daemon -e '$d = HTTP::Daemon->new(LocalPort => 8000) or  +die $!; while 
($c = $d->accept) { while ($r = $c->get_request) { +$c->send_file_response(".".$r->url->path) } }'

HTTP::Daemon comes preinstalled on many Linux distribution and thus works out of the box.

Credit goes to Anonymous Monk

Perl

perl -MHTTP::Daemon -e '$d = HTTP::Daemon->new(LocalPort => 8000) or  +die $!; while 
($c = $d->accept) { while ($r = $c->get_request) { +$c->send_file_response(".".$r->url->path) } }'

HTTP::Daemon comes preinstalled on many Linux distribution and thus works out of the box.

Credit goes to Anonymous Monk

@mayrund

This comment has been minimized.

Show comment Hide comment
@mayrund

mayrund Jul 28, 2015

Thank you!

mayrund commented Jul 28, 2015

Thank you!

@carlos-jenkins

This comment has been minimized.

Show comment Hide comment
@carlos-jenkins

carlos-jenkins Sep 1, 2015

Yet another. This is basically SimpleHTTPServer with serving folder and IP parameters. Plus the hability to remove the serving folder and later recreate it.

https://github.com/carlos-jenkins/webdev

Installation

pip install webdev

Usage

$ webdev --help
usage: webdev [-h] [-v] [--version] [-i IP] [-p PORT] [path]

Development Web Server

positional arguments:
  path                  Path to serve. Default: Current directory.

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity level
  --version             show program's version number and exit
  -i IP, --ip IP        IP to bind to. Default: 0.0.0.0
  -p PORT, --port PORT  Port to listen to. Default: 8080.

Yet another. This is basically SimpleHTTPServer with serving folder and IP parameters. Plus the hability to remove the serving folder and later recreate it.

https://github.com/carlos-jenkins/webdev

Installation

pip install webdev

Usage

$ webdev --help
usage: webdev [-h] [-v] [--version] [-i IP] [-p PORT] [path]

Development Web Server

positional arguments:
  path                  Path to serve. Default: Current directory.

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity level
  --version             show program's version number and exit
  -i IP, --ip IP        IP to bind to. Default: 0.0.0.0
  -p PORT, --port PORT  Port to listen to. Default: 8080.
@beno

This comment has been minimized.

Show comment Hide comment
@beno

beno Sep 7, 2015

Crystal

Here's one for Crystal. Speedy!

crystal eval 'require "http/server"; h = HTTP::StaticFileHandler.new("."); HTTP::Server.new(8000) {|r| h.call(r) }.listen'

updated:

crystal eval 'require "http/server"; HTTP::Server.new(8000, HTTP::StaticFileHandler.new(".")).listen'

beno commented Sep 7, 2015

Crystal

Here's one for Crystal. Speedy!

crystal eval 'require "http/server"; h = HTTP::StaticFileHandler.new("."); HTTP::Server.new(8000) {|r| h.call(r) }.listen'

updated:

crystal eval 'require "http/server"; HTTP::Server.new(8000, HTTP::StaticFileHandler.new(".")).listen'
@Klestofer

This comment has been minimized.

Show comment Hide comment
@Klestofer

Klestofer Sep 27, 2015

@jhftrifork

This comment has been minimized.

Show comment Hide comment
@jhftrifork

jhftrifork Oct 17, 2015

Are there ANY which are available on a default Windows installation?

Are there ANY which are available on a default Windows installation?

@Sebb767

This comment has been minimized.

Show comment Hide comment
@Sebb767

Sebb767 Nov 10, 2015

The powershell one should be.

Sebb767 commented Nov 10, 2015

The powershell one should be.

@hanksudo

This comment has been minimized.

Show comment Hide comment
@hanksudo

hanksudo Dec 2, 2015

anyway to simply add allow CROS header in one line?

hanksudo commented Dec 2, 2015

anyway to simply add allow CROS header in one line?

@darthwalsh

This comment has been minimized.

Show comment Hide comment
@darthwalsh

darthwalsh Dec 5, 2015

There are a couple problems I fixed in the powershell oneliner:

  • Running without elevation, binding to http://+:8000/ fails with "Access is denied". Binding to http://localhost:8000/ instead.
  • Serving HTML as plain text content type means it won't render in the browser. Lookup content type mapping.
  • The GC was removing newlines from the file, which is awkward if you have javascript using // comments. Just open a Stream.
    • bonus: streams instead of buffers!
Add-Type -AssemblyName "System.Web";$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://localhost:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};$Hso.Stop()

I also can't figure out how to break out of the one-liner from the command line. Ctrl-C and Ctrl-Break don't do anything. Having to kill powershell.exe is annoying.

There are a couple problems I fixed in the powershell oneliner:

  • Running without elevation, binding to http://+:8000/ fails with "Access is denied". Binding to http://localhost:8000/ instead.
  • Serving HTML as plain text content type means it won't render in the browser. Lookup content type mapping.
  • The GC was removing newlines from the file, which is awkward if you have javascript using // comments. Just open a Stream.
    • bonus: streams instead of buffers!
Add-Type -AssemblyName "System.Web";$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://localhost:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};$Hso.Stop()

I also can't figure out how to break out of the one-liner from the command line. Ctrl-C and Ctrl-Break don't do anything. Having to kill powershell.exe is annoying.

@cameronkerrnz

This comment has been minimized.

Show comment Hide comment
@cameronkerrnz

cameronkerrnz Jan 15, 2016

And in case you're wondering where HTTPS is in all this...

Turns out to pretty simple with OpenSSL's s_server utility. I've just used this to help test out a load-balancer configuration before the real backend was ready (not to serve content per-se). The first line creates a self-signed certificate.

openssl req -newkey rsa:2048 -nodes -x509 -subj '/CN=name-you-want.example.com' -days 3650 -out server.cert -keyout server.key
openssl s_server -accept 7781 -cert server.cert -key server.key -WWW

Unfortunately, this does not work for HEAD requests, which is a shame, because the behaviour is to time out.

See the manual page for s_server for more info.

cameronkerrnz commented Jan 15, 2016

And in case you're wondering where HTTPS is in all this...

Turns out to pretty simple with OpenSSL's s_server utility. I've just used this to help test out a load-balancer configuration before the real backend was ready (not to serve content per-se). The first line creates a self-signed certificate.

openssl req -newkey rsa:2048 -nodes -x509 -subj '/CN=name-you-want.example.com' -days 3650 -out server.cert -keyout server.key
openssl s_server -accept 7781 -cert server.cert -key server.key -WWW

Unfortunately, this does not work for HEAD requests, which is a shame, because the behaviour is to time out.

See the manual page for s_server for more info.

@aufflick

This comment has been minimized.

Show comment Hide comment
@aufflick

aufflick Feb 10, 2016

FYI some time ago I tweaked my (perl) HTTP::Server::Brick module to make one liners easier.

perl -MHTTP::Server::Brick -e 'HTTP::Server::Brick->new(fork=>1)->mount(qw(/ .))->start'

It can also support SSL, see https://metacpan.org/pod/HTTP::Server::Brick

FYI some time ago I tweaked my (perl) HTTP::Server::Brick module to make one liners easier.

perl -MHTTP::Server::Brick -e 'HTTP::Server::Brick->new(fork=>1)->mount(qw(/ .))->start'

It can also support SSL, see https://metacpan.org/pod/HTTP::Server::Brick

@vwochnik

This comment has been minimized.

Show comment Hide comment
@vwochnik

vwochnik Mar 5, 2016

For Go, there is a simple HTTP server at https://github.com/vwochnik/gost

go install vwochnik/gost

Then, simply run

gost

vwochnik commented Mar 5, 2016

For Go, there is a simple HTTP server at https://github.com/vwochnik/gost

go install vwochnik/gost

Then, simply run

gost
@maximveksler

This comment has been minimized.

Show comment Hide comment
@maximveksler

maximveksler Apr 21, 2016

no pul requests with gist, made a syntactic sugar fix to php https://gist.github.com/maximveksler/a2651d78f1c9da6a686332780d3f12f4/revisions

no pul requests with gist, made a syntactic sugar fix to php https://gist.github.com/maximveksler/a2651d78f1c9da6a686332780d3f12f4/revisions

@qwIvan

This comment has been minimized.

Show comment Hide comment
@qwIvan

qwIvan Apr 23, 2016

install
npm install anywhere -g

run
anywhere

qwIvan commented Apr 23, 2016

install
npm install anywhere -g

run
anywhere

@withakay

This comment has been minimized.

Show comment Hide comment
@withakay

withakay May 1, 2016

Haskell (via the maid module https://hackage.haskell.org/package/maid).

install
cabal install maid

serve cwd on default port 3000
maid

serve on another port
maid 5000

withakay commented May 1, 2016

Haskell (via the maid module https://hackage.haskell.org/package/maid).

install
cabal install maid

serve cwd on default port 3000
maid

serve on another port
maid 5000

@samclearman

This comment has been minimized.

Show comment Hide comment
@samclearman

samclearman May 12, 2016

  1. Do any of these support ipv6?
  2. Can I change the 404 page for any of them?
  1. Do any of these support ipv6?
  2. Can I change the 404 page for any of them?
@robinclart

This comment has been minimized.

Show comment Hide comment
@robinclart

robinclart Jun 24, 2016

One more for Ruby using Rack.

ruby -r rack -e "Rack::Server.start && run(Rack::Directory.new('./public'))"

One more for Ruby using Rack.

ruby -r rack -e "Rack::Server.start && run(Rack::Directory.new('./public'))"
@matrunchyk

This comment has been minimized.

Show comment Hide comment
@matrunchyk

matrunchyk Jun 27, 2016

For Laravel (PHP):

php artisan serve

or

php artisan serve --host=127.0.0.1 --port=8000

For Laravel (PHP):

php artisan serve

or

php artisan serve --host=127.0.0.1 --port=8000

@hickford

This comment has been minimized.

Show comment Hide comment
@hickford

hickford Aug 2, 2016

I like "Ran: a simple static web server written in Go" https://github.com/m3ng9i/ran

ran -p 8000

hickford commented Aug 2, 2016

I like "Ran: a simple static web server written in Go" https://github.com/m3ng9i/ran

ran -p 8000
@ebraminio

This comment has been minimized.

Show comment Hide comment
@ebraminio

ebraminio Aug 12, 2016

Mine, zero install if node.js available: pad.js.org, source
curl pad.js.org | node
Additionatlly, it supports [cross-domain] browser console/terminal/browser drag&drop uploads and regular and multipart (HTTP 206) downloads

ebraminio commented Aug 12, 2016

Mine, zero install if node.js available: pad.js.org, source
curl pad.js.org | node
Additionatlly, it supports [cross-domain] browser console/terminal/browser drag&drop uploads and regular and multipart (HTTP 206) downloads

@yaasita

This comment has been minimized.

Show comment Hide comment
@yaasita

yaasita Sep 6, 2016

docker run -d -p 8080:80 --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4-alpine

yaasita commented Sep 6, 2016

docker run -d -p 8080:80 --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4-alpine
@mcmillhj

This comment has been minimized.

Show comment Hide comment
@mcmillhj

mcmillhj Sep 20, 2016

Can use netcat on *nix machines:

while true ; do nc -l 80 < test.html ; done

Can use netcat on *nix machines:

while true ; do nc -l 80 < test.html ; done

@souenzzo

This comment has been minimized.

Show comment Hide comment
@souenzzo

souenzzo Oct 2, 2016

darkhttpd . (deps: darkhttp)

souenzzo commented Oct 2, 2016

darkhttpd . (deps: darkhttp)

@gbc921

This comment has been minimized.

Show comment Hide comment
@gbc921

gbc921 Nov 9, 2016

How about nweb (previously from IBM)?
Example: nweb 8181 /home/nwebdir &

gbc921 commented Nov 9, 2016

How about nweb (previously from IBM)?
Example: nweb 8181 /home/nwebdir &

@MW3000

This comment has been minimized.

Show comment Hide comment
@MW3000

MW3000 Nov 11, 2016

Pharo Smalltalk:

(ZnServer startDefaultOn: 8000) delegate: (ZnStaticFileServerDelegate new directory: '/var/www' asFileReference; yourself).

MW3000 commented Nov 11, 2016

Pharo Smalltalk:

(ZnServer startDefaultOn: 8000) delegate: (ZnStaticFileServerDelegate new directory: '/var/www' asFileReference; yourself).
@mohanraj-r

This comment has been minimized.

Show comment Hide comment
@mohanraj-r

mohanraj-r Nov 24, 2016

Following is the same implementation in golang. Although technically it is not a one-liner and requires you to type out the contents in a file ..etc, I have seen it perform 10x faster (req/sec) than the Python 2.7.10 / 3.5 equivalents (measured using apachebench ab -n 1000 ..).

main.go

import "net/http"

func main() {
   http.ListenAndServe(":8000", http.FileServer(http.Dir(".")))
}

> go run main.go

mohanraj-r commented Nov 24, 2016

Following is the same implementation in golang. Although technically it is not a one-liner and requires you to type out the contents in a file ..etc, I have seen it perform 10x faster (req/sec) than the Python 2.7.10 / 3.5 equivalents (measured using apachebench ab -n 1000 ..).

main.go

import "net/http"

func main() {
   http.ListenAndServe(":8000", http.FileServer(http.Dir(".")))
}

> go run main.go

@olejorgenb

This comment has been minimized.

Show comment Hide comment
@olejorgenb

olejorgenb Dec 26, 2016

Python 3: Restrict access to connections from localhost: python -m http.server 8000 --bind 127.0.0.1 [1]

olejorgenb commented Dec 26, 2016

Python 3: Restrict access to connections from localhost: python -m http.server 8000 --bind 127.0.0.1 [1]

@mholt

This comment has been minimized.

Show comment Hide comment
@mholt

mholt Jan 3, 2017

Caddy does all of this and without any dependencies (plus it runs anywhere):

$ caddy -port 8000

mholt commented Jan 3, 2017

Caddy does all of this and without any dependencies (plus it runs anywhere):

$ caddy -port 8000
@cheater

This comment has been minimized.

Show comment Hide comment
@cheater

cheater Jan 3, 2017

@gordondiggs you can use <(echo ...) in bash to simulate files. Maybe that could hrlp with Go.

cheater commented Jan 3, 2017

@gordondiggs you can use <(echo ...) in bash to simulate files. Maybe that could hrlp with Go.

@nabijaczleweli

This comment has been minimized.

Show comment Hide comment
@nabijaczleweli

nabijaczleweli Jan 10, 2017

Rust has http:

$ cargo install https
$ http
Hosting "." on port 8000...
Ctrl-C to stop.

Rust has http:

$ cargo install https
$ http
Hosting "." on port 8000...
Ctrl-C to stop.
@codeflows

This comment has been minimized.

Show comment Hide comment
@codeflows

codeflows Jan 17, 2017

Following up on the Go example by @mohanraj-r, you can also install gommand and run

gommand 'http.ListenAndServe(":8000", http.FileServer(http.Dir(".")))'

directly from the command line without creating an intermediate source file.

Following up on the Go example by @mohanraj-r, you can also install gommand and run

gommand 'http.ListenAndServe(":8000", http.FileServer(http.Dir(".")))'

directly from the command line without creating an intermediate source file.

@kristianlm

This comment has been minimized.

Show comment Hide comment
@kristianlm

kristianlm Feb 2, 2017

Here's how you'd do something like that in CHICKEN:

chicken-install -s spiffy
csi -R spiffy -e '(root-path ".") (start-server port: 8008)'

Note that does no directory listing, so you have to include the filenames in your url. Directory listings make things uglier:

chicken-install -s spiffy-directory-listing
csi -R spiffy-directory-listing -R spiffy -e '(handle-directory spiffy-directory-listing) (root-path ".") (start-server port: 8008)'

Here's how you'd do something like that in CHICKEN:

chicken-install -s spiffy
csi -R spiffy -e '(root-path ".") (start-server port: 8008)'

Note that does no directory listing, so you have to include the filenames in your url. Directory listings make things uglier:

chicken-install -s spiffy-directory-listing
csi -R spiffy-directory-listing -R spiffy -e '(handle-directory spiffy-directory-listing) (root-path ".") (start-server port: 8008)'
@sincarne

This comment has been minimized.

Show comment Hide comment
@sincarne

sincarne Feb 16, 2017

Similar to ibaaj, I have the following function in my bash setup:

function serve() {
	if [ $# -eq 0 ]; then
		php -S localhost:8000
	else
		php -S localhost:"$@"
	fi
}

If you run serve, it starts the server on port 8000. If you supply an argument, it expects that argument to be the port number, and uses that instead.

Similar to ibaaj, I have the following function in my bash setup:

function serve() {
	if [ $# -eq 0 ]; then
		php -S localhost:8000
	else
		php -S localhost:"$@"
	fi
}

If you run serve, it starts the server on port 8000. If you supply an argument, it expects that argument to be the port number, and uses that instead.

@jeremejazz

This comment has been minimized.

Show comment Hide comment
@jeremejazz

jeremejazz Feb 27, 2017

@matrunchyk I don't think that's for running static html files. That is used to run a laravel framework. Although you might see your static files, you are still required to install Laravel framework. Just use the built-in php server to run simple webpages (as aready included on the list)

jeremejazz commented Feb 27, 2017

@matrunchyk I don't think that's for running static html files. That is used to run a laravel framework. Although you might see your static files, you are still required to install Laravel framework. Just use the built-in php server to run simple webpages (as aready included on the list)

@ThePacketBender

This comment has been minimized.

Show comment Hide comment
@ThePacketBender

ThePacketBender Mar 15, 2017

$ go get github.com/yudai/gotty
$ $GOPATH/bin/gotty -a 127.0.0.1 -p 8000 -w cat file.ext

$ go get github.com/yudai/gotty
$ $GOPATH/bin/gotty -a 127.0.0.1 -p 8000 -w cat file.ext

@Grinnz

This comment has been minimized.

Show comment Hide comment
@Grinnz

Grinnz Mar 29, 2017

For a pre-built Mojolicious (perl) solution with directory listings:

$ cpan App::SimpleHTTPServer
$ serve_dir

(defaults to port 8000)

Grinnz commented Mar 29, 2017

For a pre-built Mojolicious (perl) solution with directory listings:

$ cpan App::SimpleHTTPServer
$ serve_dir

(defaults to port 8000)

@3rdp

This comment has been minimized.

Show comment Hide comment
@3rdp

3rdp Apr 16, 2017

$ npm install -g serve
$ serve .

(this will host . at localhost:5000)

3rdp commented Apr 16, 2017

$ npm install -g serve
$ serve .

(this will host . at localhost:5000)

@yihui

This comment has been minimized.

Show comment Hide comment
@yihui

yihui Apr 29, 2017

R

Using the servr package:

$ Rscript -e 'servr::httd()' -p8000

yihui commented Apr 29, 2017

R

Using the servr package:

$ Rscript -e 'servr::httd()' -p8000
@rosenfeld

This comment has been minimized.

Show comment Hide comment
@rosenfeld

rosenfeld Jun 7, 2017

Sometimes I want to check the gzipped size when comparing solutions. Here's how you can do it with a one liner in Ruby assuming the rack gem is installed:

rackup -p 5000 < <(echo "use Rack::Deflate; use Rack::Static, root: Dir.pwd, urls: [''], index: 'index.html'; run ->(env){[404, {}, []]}")

Sometimes I want to check the gzipped size when comparing solutions. Here's how you can do it with a one liner in Ruby assuming the rack gem is installed:

rackup -p 5000 < <(echo "use Rack::Deflate; use Rack::Static, root: Dir.pwd, urls: [''], index: 'index.html'; run ->(env){[404, {}, []]}")

@derekedelaney

This comment has been minimized.

Show comment Hide comment
@derekedelaney

derekedelaney Jun 14, 2017

I recently used ngrok to help me serve files.
You can download to install on Windows or brew cask install ngrok on Mac.
To run in this example use ngrok http 8000.

I recently used ngrok to help me serve files.
You can download to install on Windows or brew cask install ngrok on Mac.
To run in this example use ngrok http 8000.

@lyman

This comment has been minimized.

Show comment Hide comment
@lyman

lyman Jun 16, 2017

For twistd 17.1.0,port format should be twistd -n web -p 'tcp:port=8081' --path .

lyman commented Jun 16, 2017

For twistd 17.1.0,port format should be twistd -n web -p 'tcp:port=8081' --path .

@focusaurus

This comment has been minimized.

Show comment Hide comment
@focusaurus

focusaurus Jul 20, 2017

If you have npm version 5.2 or newer, you can one-liner it with npx node-static -p 8000

If you have npm version 5.2 or newer, you can one-liner it with npx node-static -p 8000

@hansnans

This comment has been minimized.

Show comment Hide comment
@hansnans

hansnans Aug 1, 2017

(python) static localhost 8080 path

hansnans commented Aug 1, 2017

(python) static localhost 8080 path

@qwIvan

This comment has been minimized.

Show comment Hide comment
@qwIvan

qwIvan Aug 13, 2017

npm install -g anywhere
anywhere
or
npx anywhere

qwIvan commented Aug 13, 2017

npm install -g anywhere
anywhere
or
npx anywhere

@konfou

This comment has been minimized.

Show comment Hide comment
@konfou

konfou Aug 14, 2017

On darkhttpd referred before, it can be quickly downloaded, built and run by doing:

curl -L unix4lyfe.org/gitweb/darkhttpd/blob_plain/HEAD:/darkhttpd.c | cc -O2 -o darkhttpd -xc -
darkhttpd . --port 8000

Similarly for, the also referred before, nweb:

curl -L raw.githubusercontent.com/ankushagarwal/nweb/master/nweb23.c | cc -O2 -o nweb -xc -
nweb 8000 . &

And yet another one is tiny:

curl -L raw.githubusercontent.com/shenfeng/tiny-web-server/master/tiny.c | cc -O2 -o tiny -xc -
tiny 8000

konfou commented Aug 14, 2017

On darkhttpd referred before, it can be quickly downloaded, built and run by doing:

curl -L unix4lyfe.org/gitweb/darkhttpd/blob_plain/HEAD:/darkhttpd.c | cc -O2 -o darkhttpd -xc -
darkhttpd . --port 8000

Similarly for, the also referred before, nweb:

curl -L raw.githubusercontent.com/ankushagarwal/nweb/master/nweb23.c | cc -O2 -o nweb -xc -
nweb 8000 . &

And yet another one is tiny:

curl -L raw.githubusercontent.com/shenfeng/tiny-web-server/master/tiny.c | cc -O2 -o tiny -xc -
tiny 8000
@Nakilon

This comment has been minimized.

Show comment Hide comment
@Nakilon

Nakilon Sep 16, 2017

These versions of adsf gem are currently available: (1.2.1, 1.2.0, 1.1.1, 1.0.1, 1.0)
All above the 1.0 require Ruby >=2.2.2 because of Rack.

So Ruby 2.0 can run only asdf 1.0 or do a gem install rack --version 1.6.0 before installing the latest adsf.

Nakilon commented Sep 16, 2017

These versions of adsf gem are currently available: (1.2.1, 1.2.0, 1.1.1, 1.0.1, 1.0)
All above the 1.0 require Ruby >=2.2.2 because of Rack.

So Ruby 2.0 can run only asdf 1.0 or do a gem install rack --version 1.6.0 before installing the latest adsf.

@rwenz3l

This comment has been minimized.

Show comment Hide comment
@rwenz3l

rwenz3l Sep 19, 2017

Twisted (Python) changed the way ports are set, a proper one-liner would be:

twistd --nodaemon web --port "tcp:port=8888" --path=/path/to/serve

or in a shorter version:

twistd -n web -p "tcp:port=8000" --path .

rwenz3l commented Sep 19, 2017

Twisted (Python) changed the way ports are set, a proper one-liner would be:

twistd --nodaemon web --port "tcp:port=8888" --path=/path/to/serve

or in a shorter version:

twistd -n web -p "tcp:port=8000" --path .

@englishextra

This comment has been minimized.

Show comment Hide comment
@englishextra

englishextra Oct 5, 2017

isn't it

ruby -run -e httpd 

not:

ruby -run -ehttpd 

there are other -flags that need space after them
also note the last revision of the gist is of 7 Jul 2013.

englishextra commented Oct 5, 2017

isn't it

ruby -run -e httpd 

not:

ruby -run -ehttpd 

there are other -flags that need space after them
also note the last revision of the gist is of 7 Jul 2013.

@soulfly

This comment has been minimized.

Show comment Hide comment
@soulfly

soulfly Oct 23, 2017

Is it possible to test a simple POST request with any of these 1 liners?
I just need to dump all input params to log

soulfly commented Oct 23, 2017

Is it possible to test a simple POST request with any of these 1 liners?
I just need to dump all input params to log

@liuyang1

This comment has been minimized.

Show comment Hide comment
@liuyang1

liuyang1 Nov 10, 2017

I had use Python's SimpleHTTPServer. It's simple and fast.

But when serve a big folder contains tons of files, I want basic filename searching.

Do you know any HTTP server support this function?

I use Everything in Windows. It support HTTP service. For now, I want a linux service.

Thanks for your sharing.

I had use Python's SimpleHTTPServer. It's simple and fast.

But when serve a big folder contains tons of files, I want basic filename searching.

Do you know any HTTP server support this function?

I use Everything in Windows. It support HTTP service. For now, I want a linux service.

Thanks for your sharing.

@guicho271828

This comment has been minimized.

Show comment Hide comment
@guicho271828

guicho271828 Nov 12, 2017

common lisp with roswell:

 ros install clack
 clackup <(echo "(lack:builder (:static :path #'identity) #'identity)")

common lisp with roswell:

 ros install clack
 clackup <(echo "(lack:builder (:static :path #'identity) #'identity)")
@augnustin

This comment has been minimized.

Show comment Hide comment
@augnustin

augnustin Nov 22, 2017

Regarding the 2.X python version, I did not like error when pressing Ctrl+C:

^CTraceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/SimpleHTTPServer.py", line 235, in <module>
    test()
  File "/usr/lib/python2.7/SimpleHTTPServer.py", line 231, in test
    BaseHTTPServer.test(HandlerClass, ServerClass)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 610, in test
    httpd.serve_forever()
  File "/usr/lib/python2.7/SocketServer.py", line 231, in serve_forever
    poll_interval)
  File "/usr/lib/python2.7/SocketServer.py", line 150, in _eintr_retry
    return func(*args)
KeyboardInterrupt

So I muted stderr.

Here' full command with port as first argument (from previous comments):

function serve() {
  port="${1:-3000}"
  python -m SimpleHTTPServer $port 2> /dev/null
}

If someone has a cleanest solution to achieve this, it is welcome! 😄

augnustin commented Nov 22, 2017

Regarding the 2.X python version, I did not like error when pressing Ctrl+C:

^CTraceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/SimpleHTTPServer.py", line 235, in <module>
    test()
  File "/usr/lib/python2.7/SimpleHTTPServer.py", line 231, in test
    BaseHTTPServer.test(HandlerClass, ServerClass)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 610, in test
    httpd.serve_forever()
  File "/usr/lib/python2.7/SocketServer.py", line 231, in serve_forever
    poll_interval)
  File "/usr/lib/python2.7/SocketServer.py", line 150, in _eintr_retry
    return func(*args)
KeyboardInterrupt

So I muted stderr.

Here' full command with port as first argument (from previous comments):

function serve() {
  port="${1:-3000}"
  python -m SimpleHTTPServer $port 2> /dev/null
}

If someone has a cleanest solution to achieve this, it is welcome! 😄

@Globik

This comment has been minimized.

Show comment Hide comment
@Globik

Globik Jan 26, 2018

And in C?

Globik commented Jan 26, 2018

And in C?

@codarrenvelvindron

This comment has been minimized.

Show comment Hide comment
@codarrenvelvindron

codarrenvelvindron Jan 28, 2018

node.js

serve-static

  • sudo npm install serve-static
  • static-server -p 8000

node.js

serve-static

  • sudo npm install serve-static
  • static-server -p 8000
@mildmojo

This comment has been minimized.

Show comment Hide comment
@mildmojo

mildmojo Feb 2, 2018

Modern npm ships with npx, which will execute a command from an npm package if it's already installed or fetch the package it, run the command, and then remove the package again. So any node example can be shortened to things like:

npx static-server
npx http-server

mildmojo commented Feb 2, 2018

Modern npm ships with npx, which will execute a command from an npm package if it's already installed or fetch the package it, run the command, and then remove the package again. So any node example can be shortened to things like:

npx static-server
npx http-server

@moshe

This comment has been minimized.

Show comment Hide comment
@moshe

moshe Feb 9, 2018

HTTP server implemented in around 50 lines of bash
https://github.com/moshe/abache/

moshe commented Feb 9, 2018

HTTP server implemented in around 50 lines of bash
https://github.com/moshe/abache/

@andrehcampos

This comment has been minimized.

Show comment Hide comment
@andrehcampos

andrehcampos Feb 9, 2018

Lets you browse files on the default host and port:

caddy browse

Short Caddyfile

Lets you browse files on the default host and port:

caddy browse

Short Caddyfile

@nabinno

This comment has been minimized.

Show comment Hide comment
@nabinno

nabinno Feb 24, 2018

Elixir:

elixir --no-halt --app inets -e ":inets.start(:httpd,[{:server_name,'s'},{:document_root,'.'},{:server_root,'.'},{:port,8000}])"

nabinno commented Feb 24, 2018

Elixir:

elixir --no-halt --app inets -e ":inets.start(:httpd,[{:server_name,'s'},{:document_root,'.'},{:server_root,'.'},{:port,8000}])"
@jkiddo

This comment has been minimized.

Show comment Hide comment
@jkiddo

jkiddo Mar 19, 2018

docker run -it --rm --name python-web -p 8000:8000 -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python -m http.server

jkiddo commented Mar 19, 2018

docker run -it --rm --name python-web -p 8000:8000 -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python -m http.server

@pezhore

This comment has been minimized.

Show comment Hide comment
@pezhore

pezhore Mar 23, 2018

Slight change to the powershell:

When requesting http://localhost:800/server/shutdown, the listener will now close, preventing you from having to kill powershell.exe

Add-Type -AssemblyName "System.Web";$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://localhost:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;if($HC.Request.RawUrl -eq '/server/shutdown'){$Hso.Stop()};$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};

pezhore commented Mar 23, 2018

Slight change to the powershell:

When requesting http://localhost:800/server/shutdown, the listener will now close, preventing you from having to kill powershell.exe

Add-Type -AssemblyName "System.Web";$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://localhost:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;if($HC.Request.RawUrl -eq '/server/shutdown'){$Hso.Stop()};$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment