title: NodeJS ReadLine - Only read the first 2 lines
body: <p>Im trying to make a Script in NodeJS, which returns the first 2 lines of a text file.</p>
  
  <p>Im currently using this code:</p>
  
  <pre><code>// content of index.js
  const fs = require('fs')
  const readline = require('readline');
  const http = require('http')  
  const port = 8080
  String.prototype.beginsWith = function (string) {
      return(this.indexOf(string) === 0);
  };
  const requestHandler = (request, response) =&gt; {  
  
    console.log(request.url)
    if (request.url == "/newlines") {
        filename = "allnames.txt"
        readline.createInterface({
              input: fs.createReadStream(filename),
              output: process.stdout
      })
  
        response.end('Hello Node.js Server!')
    }
    else {
        response.end('Go away!')
    }
  
  }
  
  const server = http.createServer(requestHandler)
  
  server.listen(port, (err) =&gt; {  
    if (err) {
      return console.log('something bad happened', err)
    }
  
    console.log(`server is listening on ${port}`)
  })
  </code></pre>
  
  <p>So this returns <strong>all</strong> lines, but I only want to let it return the first 2.</p>
  
  <p>How can I do that?</p>