title: How to make a REST-API url emit data via Socket.IO?
body: <p>I am new to NodeJS/ExpressJS and Socket.io,my question may sound funny apologies for that. As far as I have gone through the REST-API and Socket.io they have complete different applications.</p>
  
  <p>But what if...</p>
  
  <p>I have a stream API that is streaming data from sensors, now I am saving the data in Database but apart from just saving the data in database only , if my API get a call on specific route then also stream that coming data to the client side also and save it to the database, when the client disconnect the connection then it simply saved to database and when client again makes a connection then the old unseen data is streamed and the stream continues to emit the data at client side.</p>
  
  <p>For e.g. :
  let say my rest-api have urls as - </p>
  
  <ol>
  <li><p>http://:/toWatch</p></li>
  <li><p>http://:/analyses</p></li>
  <li><p>http://:/showLiveSensersData</p></li>
  </ol>
  
  <p>Now the first 2 urls have straight forward approach to send response. </p>
  
  <p>But on the third url, I want to stream the data to client via socket.
  Now my question is, if the approach is ok and if it can be done then how?
  Well what I saw was that the Socket.io instance can not be accessed in route file of expressjs.</p>
  
  <p>Any suggestion and solution or help will be much appreciated.</p>