# electron-stream

> Simple streaming wrapper around electron

Latest version **12.0.0** (published 2026-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install electron-stream
pnpm add electron-stream
yarn add electron-stream
bun add electron-stream
```

Provides the command `electron-stream`.

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 12.0.0 |
| Published | 2026-08-15 |
| First published | 2015-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=22 |
| Dependencies | 6 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 133 |
| Maintainers | juliangruber |

## Links

- npm: https://www.npmjs.com/package/electron-stream
- Repository: https://github.com/juliangruber/electron-stream
- Homepage: https://github.com/juliangruber/electron-stream#readme
- Issues: https://github.com/juliangruber/electron-stream/issues
- npm.io page: https://npm.io/package/electron-stream

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^4.4.3
- [tempy](https://npm.io/package/tempy.md) 1.0.1
- [electron](https://npm.io/package/electron.md) ^43.4.0
- [stream-read](https://npm.io/package/stream-read.md) ^1.1.2
- [serve-handler](https://npm.io/package/serve-handler.md) ^6.1.5
- [json-stringify-safe](https://npm.io/package/json-stringify-safe.md) ^5.0.1

## Recent versions

- 12.0.0 (latest) — 2026-08-15
- 11.0.2 — 2023-09-19
- 11.0.1 — 2023-09-19
- 11.0.0 — 2023-09-09
- 10.0.2 — 2022-03-23
- 10.0.1 — 2022-03-23
- 10.0.0 — 2021-11-01
- 9.1.1 — 2021-10-14
- 9.1.0 — 2021-04-08
- 9.0.0 — 2021-04-06
- 8.0.0 — 2020-07-22
- 7.1.0 — 2019-06-17
- 7.0.1 — 2019-05-02
- 7.0.0 — 2019-04-26
- 6.0.0 — 2018-10-09
- … 37 more at https://npm.io/package/electron-stream/versions

## README

# electron-stream

  Write JavaScript to `electron`, get console output back!

  [![downloads](https://img.shields.io/npm/dm/electron-stream.svg)](https://www.npmjs.org/package/electron-stream)

## Example

  Boot a hidden electron instance, log to stdout and clean up:

```js
var electron = require('electron-stream');

var browser = electron();

browser.pipe(process.stdout);

browser.write('console.log(window.location.href);');
browser.write('window.close();');
browser.end();
```

  Alternatively, use an existing http server. Note you cannot write to electron-stream when outside http server is in use.

```js
var electron = require('electron-stream');
var http = require('http');

var server = http.createServer((req, res) => {
  if (/^\/bundle\.js/.test(req.url)) {
    res.setHeader('content-type', 'application/javascript');
    res.setHeader('cache-control', 'no-cache');
    res.end('console.log("hello");window.close();');
    return;
  }

  if (req.url == '/') {
    res.setHeader('Content-Type', 'text/html');
    res.end(`<!DOCTYPE html><meta charset="utf8"><body><script src="/bundle.js"></script></body>`);
    return;
  }
});

server.listen(8000);
var browser = electron({ loc: 'http://localhost:8000' });
browser.pipe(process.stdout);
browser.end();

```

## Output streams

`electron-stream` lets you read all of the console output together, or split up into `stdout` and `stderr`:

```js
// console.log and console.error
browser.pipe(...);
browser.stdall.pipe(...);

// console.log only
browser.stdout.pipe(...);

// console.error only
browser.stderr.pipe(...);
```

## Installation

  To install as a library:

```bash
$ npm install electron-stream
```

  To install as a binary:

```bash
$ npm install -g electron-stream
$ echo "console.log('foo');window.close()" | electron-stream
```

## Travis

To use electron on travis, add this to your travis.yml:

```yml
addons:
  apt:
    packages:
      - xvfb
install:
  - export DISPLAY=':99.0'
  - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
  - npm install
```

[Source](https://github.com/rhysd/Shiba/blob/055a11a0a2b4f727577fe61371a88d8db9277de5/.travis.yml).

## API

### electron([opts])

Create a writable stream around a newly spawned `electron` which forwards written data to `electron`. This module bundles [electron-prebuilt](https://npmjs.org/package/electron-prebuilt).

Options:

  - `show`: Show the electron window. Defaults to `false`.
  - `node`:  Enable node integration. Defaults to `false`.
  - `basedir`: Set this if you need to require node modules in `node` mode
  - `static`: Serve static files from this directory at `/`
  - `loc`: a full url like `http://localhost:8080/` for using an existing http server. When `loc` is supplied, options `node`, `basedir`, and `static` are all ignored.
  - `sandbox`: Run electron with sandbox. Disable to emit debug information when using Docker. Defaults to `true`.
  
### electron#stdout
### electron#stderr
### electron#stdall

Readable streams containing the console output. `console.log` will be forwarded to `.stdout`, `console.error` to `.stderr`. `.stdall` has them both.

### electron#kill()

Kill the child process.

### electron#on('exit', fn)

Emitted when the underlying `electron` exits. There can be multiple reasons for this:

- `electron#kill()` was called
- `window.close()` was sent as a script
- there was a fatal error

## License

  MIT

---
_Source: https://npm.io/package/electron-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
