node_preamble 1.4.2

  • Installing
  • Versions
  • 95


A simple package for a better dart2js preamble for running on node.js. This package exists for ease of use if incorporating into your build system.

This preamble is suggested for use over d8.js, and provides many improvements and bug fixes, as it uses node.js's timer functions and event loop over the custom one implemented in d8.js.

The JavaScript file can be found at lib/preamble.js.

You can also get the preamble via Dart, like in the following example.

import "package:node_preamble/preamble.dart" as preamble;

main() {

Credit goes to the Dart team for creating Dart, dart2js, and the original preamble which this is derived from.


  • Keep Uri.base up to date when the current working directory changes.
  • Add .dart_tool to gitignore.


  • Make sure to replace all backslashes for cwd on Windows, not just the first.


  • Add __dirname and __filename to exposed globals. Adds ability of exposing more globals in the preamble by calling getPreamble(additionalGlobals: ["__dirname", ...]).


  • Add minified versions of the preamble accessible as lib/preamble.min.js and by calling getPreamble(minified: true).


  • Prevent encapsulation, global.self = global (old) vs. var self = Object.create(global) (new).


  • Set global.location so that Uri.base() works properly on Windows in most cases.

  • Define global.exports so that it's visible to the compiled JS.

Use this package as a library

1. Depend on it

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

  node_preamble: "^1.4.2"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

      import 'package:node_preamble/preamble.dart';
Version Uploaded Documentation Archive
1.4.2 May 25, 2018 Go to the documentation of node_preamble 1.4.2 Download node_preamble 1.4.2 archive
1.4.1 Apr 25, 2018 Go to the documentation of node_preamble 1.4.1 Download node_preamble 1.4.1 archive
1.4.0 Jun 30, 2017 Go to the documentation of node_preamble 1.4.0 Download node_preamble 1.4.0 archive
1.3.0 Mar 12, 2017 Go to the documentation of node_preamble 1.3.0 Download node_preamble 1.3.0 archive
1.2.0 Dec 3, 2016 Go to the documentation of node_preamble 1.2.0 Download node_preamble 1.2.0 archive
1.1.0 Dec 2, 2016 Go to the documentation of node_preamble 1.1.0 Download node_preamble 1.1.0 archive
1.0.0 Aug 24, 2015 Go to the documentation of node_preamble 1.0.0 Download node_preamble 1.0.0 archive


We analyzed this package on Jun 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.60.0
  • pana: 0.11.3


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


Detected platforms: Flutter, web, other

No platform restriction found in libraries.


  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use node_preamble.dart.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/preamble.dart.


Package Constraint Resolved Available
Dev dependencies
http ^0.11.0