0

Is there some way to create http server on Dart that will be compiled to JS for Node JS?

If I try to use default server

HttpServer.bind(new InternetAddress("127.0.0.1"), 8081);

and then compile this code via dart2js I'll get error when node started

Unsupported operation: InternetAddress

1 Answer 1

0

You can't use dart:io when you want to build to JS because dart:io won't be available where the build output runs. dart:io forwards to operating system calls and dart2js doesn't have any ability to translate such calls to JS (actually Node.js because JS itself doesn't provide any way at all)

You might need something like https://github.com/luizmineo/node-webkit.dart to use a custom implementation that translates to quivalent Node.js calls.

3
  • However, dart2js succeeds when provided '--categories=Server' even when dart:io is used... Perhaps some of dart:io is ok to use, but not all. Sep 24, 2016 at 13:09
  • Thanks for mentioning. You can do that, but you need a JS implementation of dart:io which doesn't exist AFAIK but one could build a wrapper that forwards to an alternative implementation. Perhaps node-webkit.dart does something like that. Sep 24, 2016 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.