Node.js interop for Dart

Dart Node.js Release License Coverage Build

This package provides Node.js interoperability for Dart.


The latest Dart SDK and Pub versions. If you plan to play with the sources, you will also need the latest Grinder version.

Installing via Pub

1. Depend on it

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

  nodejs_interop: *

2. Install it

Install this package and its dependencies from a command prompt:

$ pub get

3. Import it

Now in your Dart code, you can use:

import 'dart:js';
import 'package:nodejs_interop/nodejs_interop.dart';


The assert module

This module provides a simple set of assertion tests that can be used to test invariants:

final AssertModule _assert = require('assert');

_assert.ok(true); // Returns normally.
_assert.ok(false); // Throws a `JsAssertionError`.

The events module

This module provides the EventEmitter class:

require('events'); // Required: the `EventEmitter` class doesn't exist before this call.

var listener = allowInterop((data) => print('A "eventName" event occurred: ${data['foo']}'));
var emitter = new EventEmitter()..on('eventName', listener);
emitter.emit('eventName', new JsObject.jsify({'foo': 'bar'}));

The path module

This module provides utilities for working with file and directory paths:

final PathModule _path = require('path');

print(_path.basename('/foo/bar/baz.txt')); // "baz.txt"
print(_path.dirname('/foo/bar/baz.txt')); // "/foo/bar"

See also


Node.js interop for Dart is distributed under the Apache License, version 2.0.


Provides interoperability with Node.js APIs.