title: Passing data from backend (nodejs) to frontend javascript
body: <p>I have data in my database (MongoDB) and I am finding data from DB and saving it to array. And when button is clicked on page I want to send that data to my JavaScript file and using DOM show it on page.</p>
  
  <p>I am finding data form DB when page loads:</p>
  
  <pre><code>app.get('/', function(req, res) {
      var ipsumTextArray = [];
      Ipsum.find({}, function(err, allIpsumTexts) {
          if (err) {
              console.log(err);
          } else {
              allIpsumTexts.forEach(function(ipsum) {
                  ipsumTextArray.push(ipsum.text);
              });
          }
          res.render('home');
      });
  });
  </code></pre>
  
  <p>And in my other JavaScript file I want this function to get data from DB and do whatever I want.</p>
  
  <pre><code>function randomIpsum(text) {
      text.value = 'text from database'; // text is textarea where I want to show text
  }
  </code></pre>