Compile HttpServer from Dart to JS for NodeJS

Issue

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

Solution

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.

Answered By – Günter Zöchbauer

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.