Skip to main content

New site for Dart news and articles

For the latest Dart news, visit our new blog at  https://medium.com/dartlang .

New article on server-side programming with dart:io

Posted by Mads Ager

We've just published an article on how to use dart:io, our library for writing server-side code that runs on the standalone Dart VM. The library provides, among other things, access to files, directories, and processes. It also allows you to write HTTP servers like this simple one that just answers ‘Hello, world’ to any request:
#import('dart:io');

main() {
  var server = new HttpServer();
  server.listen('127.0.0.1', 8080);
  server.onRequest = (HttpRequest request, HttpResponse response) {
    response.outputStream.write('Hello, world'.charCodes());
    response.outputStream.close();
  };
}
To see further examples and find more out about how to use the dart:io library, take a look at the new article, An Introduction to the dart:io Library, on dartlang.org.