static_file_handler 0.2.2

  • Installing
  • Versions
  • 7


A static file Web server written in Dart. It can be used as a stand-alone command line tool or imported as a package in a Dart application.

Build Status


The static-file-handler can be used:

  • From the command line to serve files from a directory
  • To serve static files while your server side app takes care of all the dynamic requests
  • To spawn a Web server and serve static content from your app

Serve a directory from the command line

You can serve files from a directory by running the Dart script located into bin:

cd static_file_handler/bin
dart static_file_handler.dart -r <root-path> -p <port>

Optionally, you can specify a configuration file in the command line parameters.

dart static_file_handler.dart -c <config-file>

A sample config.yaml file is available in the bin folder.

For a description of all the possible parameters:

dart static_file_handler.dart --help

Serve static files from your server app

Add the package to your pubspec.yaml file:

  static_file_handler: any

Create an instance of the static file handler using the named constructor serveFolder(String directory), then call handleRequest(HttpRequest request) to serve your files. In this way your server application can handle all the dynamic requests, and you won't have to take care of the static files.

StaticFileHandler fileHandler = new StaticFileHandler.serveFolder("/path/to/folder");


You can see an example that uses the route package to feed the static file handler only with non-dynamic requests in the example/handle_request folder.

Spawn a Web server and serve static content from your app

If you just want to serve static files from your application, you can do as follows:

var fileHandler = new StaticFileHandler(path, port: port);

When you are done you can stop the Web server using fileHandler.stop().

You can see an example in the example/serve_folder folder.

Adding custom MIME types

It is possible to add custom MIME types through a method call (addMIMETypes(Map<String, String> types)), or by editing the config file.


Please file issues in the Issue Tracker


Special thanks to Anders Johnsen for the original code. Thanks to Adam Singer for his contribution.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  static_file_handler: ^0.2.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:static_file_handler/static_file_handler.dart';
Version Uploaded Documentation Archive
0.2.2 Aug 17, 2014 Go to the documentation of static_file_handler 0.2.2 Download static_file_handler 0.2.2 archive
0.2.1 Feb 11, 2014 Go to the documentation of static_file_handler 0.2.1 Download static_file_handler 0.2.1 archive
0.2.0 Nov 9, 2013 Go to the documentation of static_file_handler 0.2.0 Download static_file_handler 0.2.0 archive
0.1.3 Sep 24, 2013 Go to the documentation of static_file_handler 0.1.3 Download static_file_handler 0.1.3 archive
0.1.2 Aug 31, 2013 Go to the documentation of static_file_handler 0.1.2 Download static_file_handler 0.1.2 archive
0.1.1 Aug 31, 2013 Go to the documentation of static_file_handler 0.1.1 Download static_file_handler 0.1.1 archive
0.1.0 Jun 20, 2013 Go to the documentation of static_file_handler 0.1.0 Download static_file_handler 0.1.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.1.3 <2.0.0