Why Dart Is Gaining Momentum for Server‑Side Development
Based on the 2019 GitHub Octoverse report, JavaScript remains the most active language, but Dart’s contributor growth surged 532%, and this article explores Dart’s modern language features, isolate‑based concurrency, server‑side frameworks like shelf, and its robust tooling, highlighting its potential for backend development.
According to the Octoverse 2019 open‑source report released by GitHub, JavaScript remains the programming language with the highest activity in the global open‑source community (also in 2018), while Dart saw the highest contributor growth at 532% (2018 was Kotlin).
Although Dart’s overall popularity on Google Trends is still lower than JavaScript and TypeScript, strong promotion from Flutter and the upcoming Fuchsia OS are expected to drive a surge of interest in Dart in 2020.
Dart is a client‑optimized language for fast apps on any platform. Since the restart at version 2.0, Dart emphasizes client‑side optimizations while also providing built‑in server‑side capabilities. This article attempts to understand Dart’s current development on the server side.
Programming Language Features
As a relatively new language, Dart offers modern language features.
Type system: strong typing, type inference, null safety, immutable objects
Object‑oriented: inheritance, abstract classes, generics, mixins
Functional: lambda, higher‑order functions, closures
Asynchronous: event loop, isolates, async/await, Future, Stream
For developers familiar with TypeScript, picking up Dart for server‑side development poses little difficulty, and its event loop feels familiar to those experienced with Node.js.
Dart’s unique isolate‑based multithreading gives each isolate its own memory space and event loop, communicating only via messages, thus avoiding typical multithread deadlocks.
For compute‑intensive tasks, a new isolate can be created for non‑blocking execution. Dart also provides a high‑level isolate.compute API for running calculations in a separate isolate.
Future<List<Photo>> fetchPhotos(http.Client client) async {
final response = await client.get('https://jsonplaceholder.typicode.com/photos');
// Use the compute function to run parsePhotos in a separate isolate.
return compute(parsePhotos, response.body);
}Dart has its own VM supporting both JIT and AOT compilation. For fast start‑up scenarios such as FaaS, AOT offers much quicker launch times, while long‑running server processes benefit from JIT’s runtime performance. Through dart2js, Dart can be compiled to JavaScript, and the node_interop package enables Dart code to run on Node.js.
The presence of a JIT compiler also allows hot reload, providing a smooth local development experience for Dart server‑side projects.
Server‑Side Development Frameworks
Dart’s third‑party ecosystem lags behind JavaScript, so the language adopts a “battery‑included” approach. In addition to the low‑level dart:io package for HTTP and socket programming, the official micro‑framework shelf allows composition of middleware for request handling.
import 'dart:io';
import 'package:args/args.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;
const _hostname = 'localhost';
void main(List<String> args) async {
var parser = ArgParser()..addOption('port', abbr: 'p');
var result = parser.parse(args);
var portStr = result['port'] ?? Platform.environment['PORT'] ?? '8080';
var port = int.tryParse(portStr);
if (port == null) {
stdout.writeln('Could not parse port value "$portStr" into a number.');
exitCode = 64;
return;
}
var handler = const shelf.Pipeline()
.addMiddleware(shelf.logRequests())
.addHandler(_echoRequest);
var server = await io.serve(handler, _hostname, port);
print('Serving at http://${server.address.host}:${server.port}');
}
shelf.Response _echoRequest(shelf.Request request) =>
shelf.Response.ok('Request for "${request.url}"');However, shelf is not a full‑stack application framework, and its middleware ecosystem is limited. Other Dart server frameworks such as Aqueduct, Angel, and Jaguar show modest activity, and the previously official redstone framework has not been updated for years.
Aqueduct leverages isolates for multithreading, aiming to emulate Erlang’s actor model, but the overhead of creating isolates limits its scalability. Future frameworks may explore more possibilities with isolates, similar to Node.js’s Midway.
Toolchain
Benefiting from the “battery‑included” philosophy, Dart’s official toolchain is very powerful.
Testing: the official package:test framework and package:mockito for mocking
Scaffolding: stagehand provides various application templates
Linting: built‑in linter
Debugging & performance analysis: Dart VM’s Observatory
Package management: pub.dev
IDE support: DartPad cloud IDE and plugins for major editors
Other official tools: documentation generators, dart2js / dart2native compilers, dartaotruntime , etc.
Personal Impressions
The strong VM and complete toolchain give Dart a solid foundation for server‑side development.
The server‑side ecosystem is still immature; third‑party frameworks and cloud provider support (e.g., Google Cloud) are scarce.
No comprehensive cloud‑native solution for Dart is currently available.
The future looks promising.
These observations are based on an initial exploration of server‑side Dart; readers with practical experience are welcome to share their insights.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Node Underground
No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
