title: How to limit the number of calls in Express.js?
body: <p>I'm using express for showing the result from doing some web scraping with puppeteer but I'm having a performance issue.</p>
  
  <p>I call several times the scraper file because I want to get multiple results at once.</p>
  
  <p>For instance:</p>
  
  <pre><code>const express = require('express')
  const app = express()
  const scraper = require('./scrapers/scraper.js');
  
  app.get('/getResults', function(req, res, next) {
    const url = 'http://www.example.com';
      const val1 = new Promise((resolve, reject) =&gt; {
          scraper
              .getPrice(results, url, nights)
              .then(data =&gt; {
          resolve(data)
                  })
          .catch(err =&gt; reject('Medium scrape failed'))
      })
    const url = 'http://www.example.com';
      const val2 = new Promise((resolve, reject) =&gt; {
          scraper
              .getPrice(results, url, nights)
              .then(data =&gt; {
          resolve(data)
                  })
          .catch(err =&gt; reject('Medium scrape failed'))
  
    const url = 'http://www.example.com';
      const val3 = new Promise((resolve, reject) =&gt; {
          scraper
              .getPrice(results, url, nights)
              .then(data =&gt; {
          resolve(data)
                  })
          .catch(err =&gt; reject('Medium scrape failed'))
    const url = 'http://www.example.com';
      const val4 = new Promise((resolve, reject) =&gt; {
          scraper
              .getPrice(results, url, nights)
              .then(data =&gt; {
          resolve(data)
                  })
          .catch(err =&gt; reject('Medium scrape failed'))
    Promise.all([val1, val2, val3, val4])
      .then(data =&gt; {
          console.log(data)
      })
          .catch(err =&gt; res.status(500).send(err))
  }
  </code></pre>
  
  <p>The code above will call the scraper.js file 4 times at once, but what should I do in order to call each one once the previous one is done? I mean, when val1 is completed, it should run val2 and so on.</p>
  
  <p>In fact, my code calls the scraper file 18 times and that's not good for the computer performance since puppeteer is based with Chromium and it literally opens a new Chromium instance 18 times at once.</p>
  
  <p>I even get this error when I run it:</p>
  
  <pre><code>(node:26600) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit
  </code></pre>