Skip to content

StarpTech/dart-nodejs

Repository files navigation

dart-nodejs

Evaluate Dart as an alternative to Node.js for server-side development. This repository should serve as rough outline about the differences and similarities to Node.js.

Dart

Development

  • Built in linter.
  • Standard lib is shipped as SDK and written in Dart itself. We can debug the whole stack by pressing "F12". In Node.js the standard lib is embedded with the binary.
  • Provide pub a package manager like NPM.
  • Full vscode support.
  • Opinionated formatting like gofmt or prettier called "dartfmt".
  • Dartdocs Automated documentation generation for Pub packages.
  • Code completion, GoTo, Find References, Renaming ...
  • Great tools for testing, benchmarking and mocking.
  • Built in profiling tool shipped with the SDK observatory.

Unique features

  • Multithreading support by isolates:

    Isolates communicate by passing messages over channels, which is similar to actors in Erlang or web workers in JavaScript.

  • Smother async error handling and debugging by the concept of zones.
  • Simple and robust streaming api
  • Async module loading
  • Reduce startup times by using snapshots

    Known as app-jit snapshots

  • Dart transpiles to JavaScript.
  • Build native Android and IO's apps in record time with flutter

Language

Modern language features like:

  • Async-iterators
  • On-catch
  • Sync-iterators
  • Null-Aware Operators
  • Ranges
  • typedefs
  • cascade operator (..)
  • ...

Language characteristics:

  • Strongly typed
  • Type inference
  • Generics
  • OOP language with classes and mixin-based inheritance
  • Dart use AOT (Ahead Of Time) as well as JIT (Just In Time) compiling techniques. Read the great article Why Flutter Uses Dart
  • It's an ECMA-408 standard
  • ...

Common gotchas

  • Language syntax and concepts are very similiar (Single-threaded, Event-loop, async/await, error-handling try/catch...)
  • Use Futures as companion compared to Promises
  • Has it's own registry like NPM called https://pub.dartlang.org/
  • Dart compiles to ARM and x86 code

Interop

  • Dart can be compiled to Javascript with dart2js

Miscellaneous

  • Backed by Google like V8.
  • Battled tested by Google and many other companies
  • Faster as V8
  • Travis support
  • Google provides docker images here

My first conclusion

If you don't use Node.Js for isomorphic applications and if you don't rely heavily on other javascript libraries use Dart it will boost your productivity to Over 5000. You can still apply many concepts from Node.Js like Classes (ES6), Mixed Inheritance, Event Loop characteristics, Promises (Futures), Async/Await, try/catch, Streams, lexical scoping, closures... without to negotiate about performance and compatibility.

Demo

Installation

  1. Install DartVM
  2. Run pub get

Commands

# Run tests
pub run test ./test/test.dart
# Run benchmarks
dart ./benchmark/benchmark.dart
# Install a package
pub get $name
# Install a package as executable
pub global activate stagehand
# Run profiler
dart --observe .\main.dart
# Compile to JS
dart2js .\main.dart
# Create app snapshot
dart --snapshot=main.dart.snapshot main.dart

About

Compare https://www.dartlang.org/ and Node.js for server-side development

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages