Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mhart/epipebomb
Ignore EPIPE errors when stdout runs through a truncated pipe (such as `head`) in Node.js
https://github.com/mhart/epipebomb
Last synced: 6 days ago
JSON representation
Ignore EPIPE errors when stdout runs through a truncated pipe (such as `head`) in Node.js
- Host: GitHub
- URL: https://github.com/mhart/epipebomb
- Owner: mhart
- License: other
- Created: 2012-05-03T14:58:22.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-04-23T11:45:39.000Z (9 months ago)
- Last Synced: 2024-10-29T21:13:11.508Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 65
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# EPIPE Bomb
npm install epipebomb
By default, node throws `EPIPE` errors if `process.stdout` is being written to and
a user runs it through a pipe that gets closed while the process is still outputting
(eg, the simple case of piping a node app through `head`).This seemed a little overzealous to me, so I wrote this to suppress such errors.
## Before
#### example.js
```javascript
;(function log() {
console.log('tick')
process.nextTick(log)
})()
```#### Oh the humanity
```shell
$ node example.js | head
tick
tick
tick
tick
tick
tick
tick
tick
tick
tickevents.js:66
throw arguments[1]; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:782:11)
at Object.afterWrite (net.js:600:19)
```## After
#### example.js
```javascript
require('epipebomb')();(function log() {
console.log('tick')
process.nextTick(log)
})()
```#### Oh the joy!
```shell
$ node example.js | head
tick
tick
tick
tick
tick
tick
tick
tick
tick
tick
```## CLI usage (Node 4.x and up)
Require `epipebomb/register` from the command line
```shell
node -r epipebomb/register some-script.js | head
```or use `epipebomb` as a drop-in replacement for `node`
```shell
epipebomb some-script.js | head
```## Notes
Only the `EPIPE` error is captured on `process.stdout` - all other errors are thrown as per usual.