
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
observable-process
Advanced tools
High-level support for running, observing, and interacting with child processes in Node.js
ObservableProcess decorates the low-level Node.JS ChildProcess model with functionality to observe the behavior of processes more conveniently. In particular:
stdout and stderr with methods to search for textual contentoutput stream that combines stdout and stderrThis is useful for example when testing the terminal output of applications. Executing long-running processes through ObservableProcess will cause high memory consumption because it stores all the terminal output in RAM.
Add this library to your code base:
$ npm install observable-process
Load this library into your JavaScript code:
const { createObservableProcess } = require("observable-process")
– or –
import { createObservableProcess } from "observable-process"
The best way to provide the command to run is in the form of an argv array:
const observable = createObservableProcess(["node", "server.js"])
You can also provide the full command line to run as a string:
const observable = createObservableProcess("node server.js")
By default, the process runs in the current directory. To set the different working directory for the subprocess:
const observable = createObservableProcess("node server.js", { cwd: "~/tmp" })
You can provide custom environment variables for the process:
const observable = createObservableProcess("node server.js", {
env: {
foo: "bar",
PATH: process.env.PATH
}
})
Without a custom env parameter, ObservableProcess uses the environment
variables from the parent process.
The stdout and stderr variables of an ObservableProcess behave like normal
readable streams
and provide extra functionality to access and search their content.
// normal access to STDOUT
observable.stdout.on("data", function() {
// do something here
})
// get all content from STDOUT as a string
const text = observable.stdout.fullText()
// wait for text to appear in STDOUT
await observable.stdout.waitForText("server is online")
// wait for a regex on STDOUT
const port = await observable.stdout.waitForRegex(/running at port \d+./)
// => "running at port 3000."
Comparable functionality is available for STDERR. ObservableProcess also creates
a new output stream with the combined content of STDOUT and STDERR:
observable.output.on("data", function(data) {
// do something here
})
const text = observable.output.fullText()
await observable.output.waitForText("server is online")
const port = await observable.output.waitForRegex(/running at port \d+./)
ObservableProcess exposes the stdin stream of its underlying ChildProcess:
observable.stdin.write("my input\n")
observable.stdin.end()
observable.pid()
You can manually stop a running process via:
await observable.kill()
This sets the killed property on the ObservableProcess instance, which allows
to distinguish manually terminated processes from naturally ended ones.
To let ObservableProcess notify you when a process ended:
const exitCode = await observable.waitForEnd()
You can also listen to this in the background:
observable.waitForEnd().then(function() {
// do somehing here
})
The exit code is available via an attribute:
observable.exitCode
If you want to hack on ObservableProcess:
make testmake fixmake helpTo deploy a new version:
package.json and commit to masternpm publishFAQs
High-level support for running, observing, and interacting with child processes in Node.js
The npm package observable-process receives a total of 28 weekly downloads. As such, observable-process popularity was classified as not popular.
We found that observable-process demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.