File server

Concepts

  • Use the Deno standard library file_server.ts to run your own file server and access your files from your web browser
  • Run Deno install to install the file server locally

Example

Serve a local directory via HTTP. First install the remote script to your local file system. This will install the script to the Deno installation root’s bin directory, e.g. /home/alice/.deno/bin/file_server.

  1. deno install --allow-net --allow-read https://deno.land/std@$STD_VERSION/http/file_server.ts

You can now run the script with the simplified script name. Run it:

  1. $ file_server .
  2. Downloading https://deno.land/std@$STD_VERSION/http/file_server.ts...
  3. [...]
  4. HTTP server listening on http://0.0.0.0:4507/

Now go to http://0.0.0.0:4507/ in your web browser to see your local directory contents.

Help

Help and a complete list of options are available via:

  1. file_server --help

Example output:

  1. Deno File Server
  2. Serves a local directory in HTTP.
  3. INSTALL:
  4. deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts
  5. USAGE:
  6. file_server [path] [options]
  7. OPTIONS:
  8. -h, --help Prints help information
  9. -p, --port <PORT> Set port
  10. --cors Enable CORS via the "Access-Control-Allow-Origin" header
  11. --host <HOST> Hostname (default is 0.0.0.0)
  12. -c, --cert <FILE> TLS certificate file (enables TLS)
  13. -k, --key <FILE> TLS key file (enables TLS)
  14. --no-dir-listing Disable directory listing
  15. All TLS options are required when one is provided.