title: Nodejs fs.createReadStream event error
body: <p>I am trying to read data from a file very quickly (data from an ADC). The conversion is started on opening the file, and finished at close. I need to wait opening the file again, and wait for the currently conversion to complete.</p>
  
  <p>My problem is, that when i am opening the file very quickly nodejs wont caught the expected events. Any clue how to fix this?</p>
  
  <pre><code> node.on('input', function(){
  
              readStream = fs.createReadStream(path.location,{encoding: 'utf8'});
  
              if (readyFlag == 1) {
                  readStream.on('data',(data) =&gt; {
                      data = {payload: data/1000};
                      node.send(data);
                      console.log(`data: ${data}`);
  
                  })
              }
  
              readStream.on('open', () =&gt; {
                  console.log("file opened");
                  readyFlag = 0;
              })   
  
  
  
              readStream.on('close', () =&gt; {
                  console.log("file closed");
                  readyFlag = 1;
              })
  
              readStream.on('error', (err) =&gt; {
                  console.log(err);
              })
  
  
  
  
      })
  </code></pre>
  
  <p>I end up with the file being opened all the time.</p>