Node.js utility to control terminal stdio blocking behavior preventing output truncation
npx @tessl/cli install tessl/npm-set-blocking@2.0.0set-blocking is a Node.js utility that controls terminal stdio and stderr blocking behavior to prevent output truncation. It addresses a specific Node.js bug (#6456) where terminal output can be truncated on newer versions of Node.js (0.12+) when process.exit() is called.
npm install set-blockingconst setBlocking = require('set-blocking');const setBlocking = require('set-blocking');
// Enable blocking mode to prevent output truncation
setBlocking(true);
// Your application logic here
console.log('This output will not be truncated');
console.error('Stderr output will also be complete');
// Typically called before process.exit()
process.exit(0);set-blocking works by directly manipulating Node.js internal stream handles:
process.stdout and process.stderr streams_handle property of each streamstream.isTTY checksetBlocking() method on stream handlesControls the blocking behavior of stdout and stderr streams to ensure complete terminal output.
/**
* Sets blocking mode for stdout and stderr streams
* @param {boolean} blocking - true to enable blocking mode, false to disable
* @returns {undefined} - void function with no return value
*/
function setBlocking(blocking);Parameters:
blocking (boolean): Whether to enable (true) or disable (false) blocking mode for stdout and stderr streamsBehavior:
process.stdout and process.stderr streams_handle, is a TTY, and supports setBlockingstream._handle.setBlocking(blocking) when conditions are metUsage Examples:
const setBlocking = require('set-blocking');
// Enable blocking mode before outputting large amounts of data
setBlocking(true);
for (let i = 0; i < 10000; i++) {
console.log(`Line ${i}: Some important data that must not be truncated`);
}
// Disable blocking mode (optional - rarely needed)
setBlocking(false);Important Considerations:
process.exit() to ensure all output is flushed.setBlocking is not available.Typical Usage Pattern:
const setBlocking = require('set-blocking');
// ... your application logic ...
// Before exiting, ensure all output is complete
setBlocking(true);
console.log('Final output that must be seen');
process.exit(0);