node_interop 0.0.7

  • Installing
  • Versions
  • 32

NodeJS interop library

Build Status

Provides interface bindings for NodeJS APIs and allows writing Dart applications and libraries which can be compiled and used in NodeJS.

Unlock the full power of Dart static analysis, type system and built-in features like Futures, Streams and async/await for building NodeJS apps.


Provided API interface is Dart-centric which means Node functionality is exposed in idiomatic Dart as much as possible. For instance:

  • File system API follows dart:io interface (thanks to the awesome file package)
  • Platform API also exposed via interface provided by platform package.
  • Dart's Futures and Streams are used whenever possible.

The intention is to provide familiar and productive environment for Dart developers when working with NodeJS.


How to create a simple Node app written in Dart:

  1. Create a new Dart project. Stagehand is a great way to scaffold all the boilerplate.
  $ pub global activate stagehand
  $ mkdir my_node_app
  $ cd my_node_app
  $ stagehand package-simple # if you have .pub-cache in your PATH, or
  $ pub global run stagehand package-simple # if you don't have it in your PATH
  1. Add dependency and transformers to the generated pubspec.yaml
    node_interop: ^0.0.1

    - $dart2js
    - node_interop
  1. Create bin/main.dart and write some code:
  import 'package:node_interop/node_interop.dart';
  import 'package:node_interop/fs.dart';

  void main() async {
    var fs = new NodeFileSystem(); // access Node `fs` module
    print(fs.currentDirectory); // prints the path from `process.cwd()`
    var files = await fs.currentDirectory.list().toList();
    print(files); // lists current directory contents
  1. Compile. Pub by default assumes you are building for web so it looks for web folder. We need to explicitely tell it to look in bin/ where our main.dart is:
  $ pub build bin
  1. Run the app. Compiled app is located in build/bin/main.dart.js:
  $ # assuming you have NodeJS installed:
  $ node build/bin/main.dart.js
  $ # If everything worked well you should see your current 
  $ # directory contents printed out.


  • node_interop.dart - globals (require, exports), platform
  • fs.dart - File system abstraction
  • http.dart - HTTP client powered by Node IO and 'http' package.
  • bindings.dart - Bindings only.

Pub transformer

This library provides Pub transformer which by default processes all .dart files in the bin/ folder. The only thing it does is it prepends Node preamble to JS generated by dart2js transformer.

NodeJS modules and exports

It is possible to create a module which exposes some functionality via NodeJS exports.

Here is simple module example exporting a bang function:

// file:bin/bang.dart
import 'package:node_interop/node_interop.dart';

/// A module which exports a bang function.
void main() {
  exports.setProperty('bang', bang);

String bang(String value) {
  return value.toUpperCase() + '!';

After compiled with pub build it can be required from any JS file:

const bang = require('path/to/build/bin/bang.dart.js');
// prints out "HI!"

For such a small function the resulting bang.dart.js would be quite large (~1k lines of code). However creating Node modules like this can be considered an edge use case when you would want to mix in some functionality from Dart into an existing Node app.


In case you only need bindings to Node APIs:

library myapp;

import 'package:node_interop/bindings.dart';
import 'package:js/js.dart';

void main() {
  // Require specific modules:
  FS nodeFS = require('fs');
  OS nodeOS = require('os');
  // Use globals:

Features and bugs

Please file feature requests and bugs at the issue tracker



  • Added node_interop/test.dart library with installNodeModules() helper function. See dartdoc for more details.


  • jsObjectToMap: added null-check.
  • Added basic HTTP client implementation for Node, based on an interface from 'http' package. Use with import package:node_interop/http.dart.


  • Streamlined bindings layer and exposed as it's own library. Use import package:node_interop/bindings.dart to get access.
  • Added bindings for 'http' module (work in progress).


  • Upgraded to test package with support for running tests in Node
  • Implemented NodeFileSystem.file() and File.writeAsStringSync().


  • Added bindings for Console.


  • Switched to use official node_preamble package


  • Initial version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  node_interop: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:node_interop/node_interop.dart';
Version Uploaded Documentation Archive
0.0.7 Oct 4, 2017 Go to the documentation of node_interop 0.0.7 Download node_interop 0.0.7 archive
0.0.6 Oct 3, 2017 Go to the documentation of node_interop 0.0.6 Download node_interop 0.0.6 archive
0.0.5 Oct 1, 2017 Go to the documentation of node_interop 0.0.5 Download node_interop 0.0.5 archive
0.0.4 Jul 8, 2017 Go to the documentation of node_interop 0.0.4 Download node_interop 0.0.4 archive
0.0.3 Jul 2, 2017 Go to the documentation of node_interop 0.0.3 Download node_interop 0.0.3 archive
0.0.2 Jun 30, 2017 Go to the documentation of node_interop 0.0.2 Download node_interop 0.0.2 archive
0.0.1+2 Jun 18, 2017 Go to the documentation of node_interop 0.0.1+2 Download node_interop 0.0.1+2 archive
0.0.1+1 Jun 18, 2017 Go to the documentation of node_interop 0.0.1+1 Download node_interop 0.0.1+1 archive
0.0.1 Jun 18, 2017 Go to the documentation of node_interop 0.0.1 Download node_interop 0.0.1 archive
1.0.0-dev.11.0 Oct 5, 2018 Go to the documentation of node_interop 1.0.0-dev.11.0 Download node_interop 1.0.0-dev.11.0 archive

All 31 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0