const { Readable } = require('stream');
// Create a readable stream in object mode
const objectStream = new Readable({
objectMode: true,
read() {}
});
// Push objects to the stream
objectStream.push({ id: 1, name: 'Kai' });
objectStream.push({ id: 2, name: 'Elisabeth' });
objectStream.push(null); // Signal end of stream
// Consume the stream
objectStream.on('data', (obj) => {
console.log('Received:', obj);
});
Received: { id: 1, name: 'Kai' } Received: { id: 2, name: 'Elisabeth' }