Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
stdout-stderr
Advanced tools
The stdout-stderr npm package is a utility for capturing and manipulating the standard output (stdout) and standard error (stderr) streams in Node.js applications. It is particularly useful for testing and debugging purposes, allowing developers to intercept and inspect the output of their code.
Capture stdout
This feature allows you to capture the standard output (stdout) stream. The code sample demonstrates how to start capturing stdout, print a message, stop capturing, and then inspect the captured output.
const stdio = require('stdout-stderr');
stdio.stdout.start();
console.log('Hello, World!');
stdio.stdout.stop();
console.log(stdio.stdout.output); // ['Hello, World!\n']
Capture stderr
This feature allows you to capture the standard error (stderr) stream. The code sample demonstrates how to start capturing stderr, print an error message, stop capturing, and then inspect the captured output.
const stdio = require('stdout-stderr');
stdio.stderr.start();
console.error('An error occurred!');
stdio.stderr.stop();
console.log(stdio.stderr.output); // ['An error occurred!\n']
Combined stdout and stderr capture
This feature allows you to capture both stdout and stderr streams simultaneously. The code sample demonstrates how to start capturing both streams, print messages to both stdout and stderr, stop capturing, and then inspect the combined output.
const stdio = require('stdout-stderr');
stdio.start();
console.log('Hello, World!');
console.error('An error occurred!');
stdio.stop();
console.log(stdio.output); // ['Hello, World!\n', 'An error occurred!\n']
Suppress output
This feature allows you to suppress the output to stdout or stderr. The code sample demonstrates how to suppress stdout, print a message that will not be shown, restore stdout, and then print a message that will be shown.
const stdio = require('stdout-stderr');
stdio.stdout.suppress();
console.log('This will not be shown');
stdio.stdout.restore();
console.log('This will be shown');
The capture-console package provides similar functionality for capturing and manipulating stdout and stderr streams. It offers methods to capture, suppress, and restore console output, making it a good alternative to stdout-stderr.
The intercept-stdout package enables you to intercept and capture stdout and stderr streams. It provides a straightforward API to intercept output and perform custom actions, making it a versatile alternative to stdout-stderr.
mock stdout and stderr
Usage:
const {stdout, stderr} = require('stdout-stderr')
stdout.start() // start mocking stdout
console.log('writing to stdout') // this will not be displayed
stdout.stop() // stop mocking stdout
assert(stdout.output === 'writing to stdout') // view the output
/* options */
stdout.stripColor = false // disable automatic ansi code stripping
stdout.print = true // also output to screen
This uses the debug module so you can also see the output by setting DEBUG=stdout|stderr|*
.
FAQs
mock stdout and stderr
The npm package stdout-stderr receives a total of 148,476 weekly downloads. As such, stdout-stderr popularity was classified as popular.
We found that stdout-stderr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.