VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-readable-stream-error-event/

⇱ Node.js Readable Stream error Event - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Readable Stream error Event

Last Updated : 28 Apr, 2025

The 'error' event in Readable stream can be emitted at any time. It takes place when the hidden stream is not able to generate data due to some hidden internal failure or when the implementation of stream pushes a chunk of data which is not valid. Moreover, a single Error object is passed as an argument to the listener callback.
 

Syntax:  

Event: 'error'


Below examples illustrate the use of error event in Node.js:
Example 1:  

Output: 

Done...
{ [Error: ENOENT: no such file or directory, open 'input.txt'] errno: -2,
 code: 'ENOENT', syscall: 'open', path: 'input.text' }


Example 2:  

Output: 

Done...


Here, no error occurs so error event is not emitted.
Reference: https://nodejs.org/api/stream.html#stream_event_error_1 

Comment

Explore