How to start Dart on the server?

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

+7
source share
2 answers

The answer is yes.

For example, the following Hello.dart file:

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

when launched using the command (in windows, but also available for mac, linux)

 dart.exe Hello.dart 

displays

 "Hello World" 

This is very similar to node.js.

In addition, from the Dart editor, you can click "New> Server Application", and then the "run" command will work as an example above

Check out this file that starts the HTTP server from the command line.

Update . I wrote a blog post about it now, which should give an example and run the code

+9
source

Yes, you can run server applications written in Dart. The Dart project provides a dart: io library that contains classes and interfaces for sockets, HTTP servers, files, and directories.

A good example of a simple HTTP server written in Dart: http://www.dartlang.org/articles/io/

Code example:

 #import('dart:io'); main() { var server = new HttpServer(); server.listen('127.0.0.1', 8080); server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { response.outputStream.write('Hello, world'.charCodes()); response.outputStream.close(); }; } 
+2
source

All Articles