nodejs_interop 0.3.0

Node.js interop for Dart

Dart Node.js Release License Coverage Build

This package provides Node.js interoperability for Dart.

Requirements

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:

dependencies:
  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';

Usage

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:

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

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 os module

This module provides a number of operating system-related utility methods:

final OsModule os = require('os');

print(os.homedir()); // "/home/user"
print(os.tmpdir()); // "/tmp"

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

License

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

Changelog

This file contains highlights of what changes on each version of the Node.js interop for Dart library.

Version 0.3.0

  • Added the os module.
  • Added the convertToDart() and convertToFuture() functions.
  • Added the CpuUsage, NodejsPlatform and Promise classes.
  • Added a partial implementation of the Process class.

Version 0.2.0

  • Breaking change: renamed the PathObject class to Path.
  • Added the assert module.
  • Added the errors module.
  • Added the events module.

Version 0.1.0

  • Initial release: provides the require() function and the path module.

1. Depend on it

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

dependencies:
  nodejs_interop: "^0.3.0"

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:nodejs_interop/nodejs_interop.dart';

Platforms

Web

About

Provides interoperability with Node.js APIs.

Author

C├ędric Belin

Homepage

github.com/cedx/nodejs-interop.dart

Documentation

www.dartdocs.org/documentation/nodejs_interop/0.3.0/

Uploader

cedxbelin@gmail.com

License

MIT (LICENSE.txt)

Published

Nov 14, 2017