Will dart.... in Node.js ?

1,392 views
Skip to first unread message

Alexey Solovey

unread,
Nov 18, 2015, 1:06:06 PM11/18/15
to Dart Misc
Hello. I want to see Dart VM inside Node.js. But will be Dart use as Node.js Engine (sub-engine).
I think about scenario, where Dart work as Node.js native module. And runs like coffeescript runs through "coffee script.coffee". 
Also I thinking about interaction with C++ native module API. 

I want try Dart with C++ AMP native module, or CUDA. 

Bob Nystrom

unread,
Nov 18, 2015, 1:44:55 PM11/18/15
to General Dart Discussion
On Wed, Nov 18, 2015 at 10:06 AM, Alexey Solovey <act...@gmail.com> wrote:
Hello. I want to see Dart VM inside Node.js. But will be Dart use as Node.js Engine (sub-engine).

Is it that you want to use Dart code within Node, or the Dart virtual machine? 
 
I think about scenario, where Dart work as Node.js native module. And runs like coffeescript runs through "coffee script.coffee". 

The way this works for CoffeeScript is that it's compiled to JavaScript and then the resulting JS is run in node. Would the same work for you for Dart?

– bob

Mike Carter

unread,
Nov 18, 2015, 3:07:44 PM11/18/15
to Dart Misc
You might want to check out this project, gives you some node bindings in dart: https://github.com/dglogik/node_io.dart

Jim Simon

unread,
Nov 18, 2015, 6:41:50 PM11/18/15
to mi...@dartlang.org

I'd love to be able to run dart code compiled to JavaScript on node.js.  I tried doing this with the old js interop package, but quickly ran into issues with I/O and finding a working preamble.  It'd be great to have node.js be a target platform for dart2js or ddc.  Dart packages could then theoretically serve two communities at once.  If the resulting JS is readable, it would also help mitigate the whole "what if Google gives up on Dart?" fear since there would be a migration path.  Does the new JS interop provide a better story for this?

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Bob Nystrom

unread,
Nov 18, 2015, 6:56:08 PM11/18/15
to General Dart Discussion
On Wed, Nov 18, 2015 at 3:41 PM, Jim Simon <jim.j...@gmail.com> wrote:
I tried doing this with the old js interop package, but quickly ran into issues with I/O and finding a working preamble.  It'd be great to have node.js be a target platform for dart2js or ddc.

I think so too.
 
Dart packages could then theoretically serve two communities at once.  If the resulting JS is readable, it would also help mitigate the whole "what if Google gives up on Dart?" fear since there would be a migration path.

Yes! Readable, debuggable, JS is a key goal of DDC (as opposed to dart2js where it never was).
 
  Does the new JS interop provide a better story for this?

I'm not the best person to answer detailed questions, but my understanding is that, yes, it's a much more seamless experience.

– bob

Michael Bullington

unread,
Nov 19, 2015, 7:12:08 PM11/19/15
to mi...@dartlang.org
Hello!

Michael Bullington here, I work at DGLogik, and I'm the main developer on the aforementioned node_io project, as well as other node.js <-> Dart related projects. With these projects, we are able to ship a stable version of our IoT platform's Dart SDK to clients that can be used to create applications entirely in JavaScript. This is on both the browser, and on node.js.

Basically, to run Dart code in node.js, there are a few things you need to do.

- Compile your "main" Dart file with dart2js.
- You need to prepend code to the dart2js output file for it to be able to work in a node.js environment. I've created a pub package for mostly ease of use, as it's versioned and easily able to be integrated into a build system with Grinder or similar.


Or, if you'd just like the file itself to prepend, here it is:


If you are building for the browser, you need to do other things like Browserify, etc. Considering you are wondering about native modules, I don't believe this is in the scope of what you'd like to do?

With this setup, you can use any node.js API by using the dart:js package, including node.js native modules (we use node.js native modules when available to speed up some cryptographic operations).
The new js package introduced with Dart 1.13 should work, I haven't tried it personally. I'm not sure how it would work with CommonJS's require().

As for node_io, we use it for our purposes, but as of right now it is hardly API complete with dart:io. We intend to branch node_io out in the future, but until then it is not published on pub for this reason.
And as for using Dart code from JavaScript, we use something we built on top of the current dart2js compiler called calzone, which you can find on pub. (as a side note, can't wait to see how DDC will improve our codebase with readable JS!)

If you (or anyone else curious about the subject) would like to discuss Dart on node.js (I'll try my best), I'd love to chat on the Dart Slack channel! You can find me at @mbullington.

Jim Simon

unread,
Nov 22, 2015, 4:45:16 PM11/22/15
to mi...@dartlang.org
What I'd really like to see is for the dart compiler (either one) to be aware of node IO operations and to compile Dart IO operations down to their corresponding Node equivalent.  IIRC, right now it just doesn't do anything (maybe throws an error?)

--

Kasper Peulen

unread,
Nov 22, 2015, 6:16:23 PM11/22/15
to mi...@dartlang.org
Yes! Readable, debuggable, JS is a key goal of DDC (as opposed to dart2js where it never was).

I understand that the reasoning behind choosing ES6 instead of ES5, as with ES5 the output will still not be really readable.

The downside is of course, that we probably still need to use babel, for compiling it to ES6.

Therefore, I would hope the team to consider maybe having an option compiling Dart to typescript instead of ES6. I think this makes sense, as when compiling to typescript, the types, annotations, and soon also async/await code would not get lost in the process. 

So basically, compiling dart to typescript would probably give more readable code than compiling to ES6. Only then you would use the typescript compiler to target es5 (or es3), instead of babel.

I wonder if in that way, I could write angular2 components in Dart, that could be used by angular 2 typescript devs.
--
Kasper

John Messerly

unread,
Nov 23, 2015, 1:45:08 PM11/23/15
to General Dart Discussion, Olivier Chafik
Hi Kasper,

On Sun, Nov 22, 2015 at 3:16 PM, Kasper Peulen <kasper...@gmail.com> wrote:
Yes! Readable, debuggable, JS is a key goal of DDC (as opposed to dart2js where it never was).

I understand that the reasoning behind choosing ES6 instead of ES5, as with ES5 the output will still not be really readable.

The downside is of course, that we probably still need to use babel, for compiling it to ES6.

Therefore, I would hope the team to consider maybe having an option compiling Dart to typescript instead of ES6. I think this makes sense, as when compiling to typescript, the types, annotations, and soon also async/await code would not get lost in the process. 

Absolutely we'd consider this for DDC. It really just needs someone with time to champion it.

Currently DDC works (basically) like this:

Dart --> ES6 (with an ES5 module pattern)

Imagine if it worked more like this:

Dart --> "typed JS AST" ---> ES6 w/ modules --> ES6+ES5 module pattern
                        |--> TypeScript
                        \--> ES6 w/ Closure Compiler comments/modules

"typed JS AST" is something a bit higher level than the ES6 AST we currently emit. Something that's easy for us to transform to ES6, TS, or Closure Compiler as needed.

For anyone interested in this topic, feel free to discuss in the dev-co...@dartlang.org group.

I also created https://github.com/dart-lang/dev_compiler/issues/391 to track this feature request.

So basically, compiling dart to typescript would probably give more readable code than compiling to ES6. Only then you would use the typescript compiler to target es5 (or es3), instead of babel.

I wonder if in that way, I could write angular2 components in Dart, that could be used by angular 2 typescript devs.

It should work. But keep in mind we do not want DDC to require other transpilers! (imagine if TypeScript required running the output through Babel, which required Traceur, which required Narcissus, which required ... ).

Rat Jo

unread,
Dec 2, 2015, 1:32:57 AM12/2/15
to Dart Misc
If anyone is interested into running dart compiled to js in nodejs, just hit me. I have actually have few project that do so and work great!


On Wednesday, November 18, 2015 at 1:06:06 PM UTC-5, Alexey Solovey wrote:
Reply all
Reply to author
Forward
0 new messages