JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7844
  • Score
    100M100P100Q126929F
  • License MIT

Run node with ES6 Generators, today!

Package Exports

  • gnode
  • gnode/bin/gnode

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gnode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gnode

Run node with ES6 Generators, today!

Build Status

gnode is a very light wrapper around your node executable that ensures ES6 Generator support, even on versions of node that do not support ES6 Generators natively. Support for generators happens either through V8's native support (via the --harmony_generators flag when necessary, on node >= v0.11.3), or falling back to facebook/regenerator emulation when no native support is available (node < v0.11.3).

With gnode you can use co or suspend, or any other Generator-based flow control based module, today!

Installation

Install the gnode executable via npm:

$ npm install -g gnode

CLI Examples

The gnode executable uses whatever version of node is installed in your PATH:

Here's our example t.js file:

var co = require('co');

function sleep (ms) {
  return function (fn) {
    setTimeout(fn, ms);
  };
}

co(function* () {
  for (var i = 0; i < 5; i++) {
    console.log(i);
    yield sleep(1000);
  }
})();

This script with an ES6 Generator in it can be run using any version of node by using gnode:

☮ ~ (master) ∴ n 0.8.26

☮ ~ (master) ∴ gnode -v
v0.8.26

☮ ~ (master) ∴ gnode t.js
0
1
2
3
4

☮ ~ (master) ∴ n 0.10.21

☮ ~ (master) ∴ gnode -v
v0.10.21

☮ ~ (master) ∴ gnode t.js
0
1
2
3
4

☮ ~ (master) ∴ n 0.11.8

☮ ~ (master) ∴ gnode -v
v0.11.8

☮ ~ (master) ∴ gnode t.js
0
1
2
3
4

Programmatic API

You can also just require('gnode') in a script without any generators, and then require() any other .js file that has generators after that.

require('gnode');
var gen = require('./someGenerator');
// etc…