How to run Dart on a server?

Issue

Is there a way to run Dart code on a server, similar to how Node.js runs javascript or ruby interpreter runs ruby code? Or is it that currently it can only run in Dartium?

Solution

The answer is yes.

For example, the following file Hello.dart:

main() => print("Hello World");

when run with the command (on windows, but also available for mac, linux)

dart.exe Hello.dart

will output

"Hello World"

It is very much like node.js.

Also, from the Dart Editor, you can click “New > Server App” and then the “run” command will work like the example above

Take a look at this file which runs an http server from the command line.

Update: I’ve written a blog post about this now, which should give an example, and runnable code

Answered By – Chris Buckett

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *