Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

from-node-stream

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

from-node-stream

convert nodejs-stream into webstream

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
2.6K
-14.61%
Maintainers
1
Weekly downloads
 
Created
Source

from-node-stream

Usage Examples

Stdio Passthrough Example

Create a script that pipes process stdin through a bash process and then to stdout:

import { exec } from "child_process";
import { fromStdio } from "from-node-stream";
import { fromReadable } from "from-node-stream/fromReadable";
import { fromWritable } from "from-node-stream/fromWritable";

// Execute everything from stdin in bash and then output to stdout
await fromReadable(process.stdin)
  .pipeThrough(fromStdio(exec("bash")))
  .pipeTo(fromWritable(process.stdout));

Basic: Read and Write from Node Streams

import { exec } from "child_process";
import { fromWritable, fromReadable } from "from-node-stream";

const p = exec("sh");
// Write to stdin
const writer = fromWritable(p.stdin!).getWriter();
await writer.write("echo hello, world\n");
await writer.close();
// Read from stdout
const reader = fromReadable(p.stdout!).getReader();
let output = "";
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  output += typeof value === "string" ? value : new TextDecoder().decode(value);
}
console.log(output); // "hello, world\n"

Using fromStdioDropErr

import { exec } from "child_process";
import { fromStdioDropErr } from "from-node-stream";

const p = exec("sh");
// Write to stdin
const writer = fromStdioDropErr(p).writable.getWriter();
await writer.write("echo hello, world\n");
await writer.close();
// Read from stdout
const reader = fromStdioDropErr(p).readable.getReader();
let output = "";
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  output += typeof value === "string" ? value : new TextDecoder().decode(value);
}
console.log(output); // "hello, world\n"

Using fromStdioMergeError

import { exec } from "child_process";
import { fromStdioMergeError } from "from-node-stream";

const p = exec("sh");
// Write to stdin
const writer = fromStdioMergeError(p).writable.getWriter();
await writer.write("echo oops, error>&2 && echo hell, word\n");
await writer.close();
// Read merged stdout and stderr
const reader = fromStdioMergeError(p).readable.getReader();
let output = "";
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  output += typeof value === "string" ? value : new TextDecoder().decode(value);
}
console.log(output); // "oops, error\nhell, word\n"

Drop stderr with fromStdioDropErr

import { exec } from "child_process";
import { fromStdioDropErr } from "from-node-stream";

const p = exec("sh");
// Write to stdin
const writer = fromStdioDropErr(p).writable.getWriter();
await writer.write("echo oops, error>&2 && echo hell, word\n");
await writer.close();
// Read from stdout only (stderr dropped)
const reader = fromStdioDropErr(p).readable.getReader();
let output = "";
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  output += typeof value === "string" ? value : new TextDecoder().decode(value);
}

Development

To install dependencies:

bun install

To run:

bun run index.ts

This project was created using bun init in bun v1.1.21. Bun is a fast all-in-one JavaScript runtime.

Keywords

WebStream

FAQs

Package last updated on 18 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts