JSPM

  • Created
  • Published
  • Downloads 4215
  • Score
    100M100P100Q120815F
  • License MIT

Transform stream that executes JavaScript it receives in a real browser and outputs console output

Package Exports

  • browser-run

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 (browser-run) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

browser-run

The easiest way of running code in a browser environment.

Usage

$ echo "console.log('Hey there from ' + document.location)" | browser-run
Hey there from http://localhost:53227/

Or use browser-run programmatically:

var run = require('browser-run');

var browser = run();
browser.pipe(process.stdout);
browser.write('console.log(document.location)');
browser.end();

Example with browserify

$ browserify main.js | browser-run

or

var browserify = require('browserify');
var browser = require('browser-run');

browserify('main.js').bundle().pipe(browser()).pipe(process.stdout);

CLI

$ browser-run --help
Run JavaScript in a browser.
Write code to stdin and receive console output on stdout.
Usage: browser-run [OPTIONS]

Options:
  --browser, -b  Browser to use. Available if installed: chrome, firefox, ie, phantom, safari  [default: "phantom"]
  --port, -p     Starts listening on that port and waits for you to open a browser
  --static, -s   Serve static assets from this directory
  --help, -h     Print help

API

run([opts])

Returns a duplex stream and starts a webserver.

opts can be:

  • port: If speficied, no browser will be started, so you can point one yourself to http://localhost/<port>
  • browser: Browser to use. Defaults to phantom. Available if installed:
    • chrome
    • firefox
    • ie
    • phantom
    • safari
  • static: Serve static files from this directory

run#stop()

Stop the underlying webserver.

Installation

With npm do

$ npm install browser-run    # for library
$ npm install -g browser-run # for cli

License

(MIT)