Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a Node library in a Dart server

Is it possible to import a Node module (NPM) into a Dart server?

From what I can see, JS interop only works with client-side Dart, is that right?

Can a Javascript library be included into a pubspec file and the content of that library used in the server via js interop?

Is there some other way of including JS in Dart server code?

like image 853
kpg Avatar asked Jul 08 '14 11:07

kpg


People also ask

Is dart good for server side?

Dart tooling is excellent and it makes fun to develop. If you're using a library like gRPC, then migrating to another server language is also not that big of a task, since you can just generate the server stub for another language, and all the work that has gone into designing your database has also been done already.

Is dart faster than NodeJS?

It's actually faster than other compiled languages like Java. However, Dart proved to be much faster when benchmarked against JavaScript. You can refer to the benchmark of Dart against NodeJS here.

Is dart client side or server side?

Dart is a Google-produced programming language that has slowly been gaining traction, particularly since its 1.0 release last year. While Dart has thus far been seen as a promising alternative to JavaScript in the browser, I'd like to argue that like Node. js, the true promise of Dart is actually on the server side.

Can I use dart for backend?

With Dart, you can create console and mobile applications, web scripts, and do backend programming.


2 Answers

If you want to run your Dart app on NodeJS, you need to use package:node_preamble. https://pub.dev/packages/node_preamble

A prominent package that does that is Sass. In fact, when you compile Sass to CSS, you are most likely using the Dart compiler running on Node. Examining the repository will give you some hints how they go about it: Dart Sass

From what I can see, JS interop only works with client-side Dart, is that right?

Nope If you examine Dart Sass implementation, you will see interop declarations in it. You should be able to create Dart wrappers around JS functionality. Another example that does this is: Firestore for web

The interop uses package:js

edit: just realized how old the original question was :) Ohh well..

like image 180
Daniel V. Avatar answered Oct 17 '22 02:10

Daniel V.


Of what I have heard you can build Dart to JS and run the result in Node.js. I guess here you can use Node modules too. Using a Node module when running as Dart is not possible I guess.

like image 28
Günter Zöchbauer Avatar answered Oct 17 '22 00:10

Günter Zöchbauer