title: Collect data from multiple requests nodejs
body: <p><strong>Environment</strong>: nodejs 17.2, expressjs 4.17</p>
  <p><strong>Task</strong>: Data arrives at the url of the type &quot;/user-actions&quot; from different servers at a rate of about 2 requests per second. It is necessary to aggregate them and send them to another server once a second.</p>
  <p><strong>For example</strong>:</p>
  <ul>
  <li>Request #1: {userId: 1, action: &quot;hitOne&quot;}</li>
  <li>Request #2: {userId: 2, action: &quot;hitFive&quot;}</li>
  <li>Request #3: {userId:1, action: &quot;hitFive&quot;}</li>
  </ul>
  <p>It is necessary to get 2 objects</p>
  <pre><code>const data = [{userId: 1, action: &quot;hitOne&quot;}, {userId: 2, action: &quot;hitFive&quot;}]
  </code></pre>
  <p>and</p>
  <pre><code>const data = [{userId: 1, action: &quot;hitFive&quot;}]
  </code></pre>
  <p>Each of these objects is sent to another server 1 time per second, something like this</p>
  <pre><code>http.post('http://newserver.url/user-actions', {data});
  </code></pre>
  <p>I was thinking of making a variable in which to record everything that comes in the request and send this variable to a new server once a second on a timer.
  But something tells me: or there will be problems with the variable (for example, due to concurrent request) and there will not always be the data I was waiting for, or some nonsense will come out with the timer.</p>
  <p>How to implement such a scenario correctly?</p>