title: How to fix 'Cannot read property 'includes' of undefined' in nodejs? [Script]
body: <p>I'm setting up a new server, and want to run a nodejs script to discord. But the problem is; it posts errors after the script is started/or running.</p>
  
  <p>I have tried to contact "author" without an answer on GitHub to get it fixed, and I did try tested on other servers I have online, but it says the same error. (incl downgrade of nodejs/npm version.)</p>
  
  <p>The code I did found is from this GitHub page: <a href="https://github.com/Triniayo/nodejs-discord-csgoupdate" rel="nofollow noreferrer">https://github.com/Triniayo/nodejs-discord-csgoupdate</a></p>
  
  <pre><code>// Requirements
  const { Client } = require('discord.js');
  const fs = require('fs');
  const Parser = require('rss-parser');
  const htmlToText = require('html-to-text');
  const log = require('npmlog');
  
  // Load Config
  const cfg = require('./config.json');
  
  // Create feeder instance
  let rssParser = new Parser({
      // Renaming 'content:encoded' to 'contentHtml' because it won't be useable otherwise
      customFields: {
          item: [
              ['content:encoded', 'contentHtml']
          ]
      },
      // Setting User Agent
      headers: {
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
      }
  });
  
  // Setting variables for the RSS output
  let updateTitle;
  let updateURL;
  let updateContent;
  let updateDate;
  
  // Setting last update variable
  let lastUpdate;
  
  function getLastUpdate() {
      // Getting date of last update from check-update.txt file
      let dateFromFile = fs.readFileSync('check-update.txt');
      lastUpdate = dateFromFile.toString();
  }
  
  // Getting last date from check-update.txt file every 5 seconds
  setInterval(getLastUpdate, 5000);
  
  // Create Discord Bot Instance
  const bot = new Client();
  
  // Logging into Bot Account
  bot.on('ready', () =&gt; {
      log.info('discord', `Logged in as ${bot.user.tag} (User ID: ${bot.user.id}) on ${bot.guilds.size} server(s)`);
      bot.user.setActivity('Fetching Updates');
  
      // Checking every 10 seconds if there's a new update, and if it's been posted already
      setInterval(getUpdate, 10000);
  });
  
  function getUpdate() {
      // Get current date and edit format
      let getDate = new Date();
      let date = [
          getDate.getFullYear(),
          ('0' + (getDate.getMonth() + 1)).slice(-2),
          ('0' + getDate.getDate()).slice(-2)
      ].join('-');
  
      // Fetching updates from CS:GO Blog
      (async () =&gt; {
          // Setting RSS Feed URL
          let feed = await rssParser.parseURL('http://blog.counter-strike.net/index.php/category/updates/feed/');
  
          // Setting items into variables
          feed.items.forEach(item =&gt; {
              if (item.isoDate.includes(`${date}`)) {
                  updateTitle = item.title;
                  updateURL = item.link;
                  updateContent = item.contentHtml;
                  updateDate = item.isoDate;
              }
          });
  
          // Converting from HTML to readable text
          let format = htmlToText.fromString(updateContent, {
              wordwrap: 130
          });
  
          // Limiting the update to 10 lines
          let updateNotes = format.split('\n', 10);
  
          if (updateDate.includes(`${date}`)) {
              if (lastUpdate !== date) {
                  bot.channels.get(cfg.channelid).send("@everyone A new CS:GO Update has been released!", {
                      embed: {
                        "title": `${updateTitle}`,
                        "description": `${updateNotes.join('\n')}...\n\n[Continue reading on the CS:GO Blog](${updateURL})`,
                        "url": `${updateURL}`,
                        "color": 5478908,
                        "thumbnail": {
                          "url": "https://raw.githubusercontent.com/Triniayo/nodejs-discord-csgoupdate/master/csgo-icon.png"
                        }
                      }
                  });
  
                  // Storing date of the latest update in the check-update.txt
                  fs.writeFileSync('check-update.txt', `${date}`)
              }
          } else {
              // Do nothing if update has been posted already.
          }
      })();
  }
  
  // Logging into the Bot Account
  bot.login(cfg.token);
  </code></pre>
  
  <p>On below this, is the error, I'm getting after I did updated nodejs &amp; npm to the newest version.</p>
  
  <pre class="lang-sh prettyprint-override"><code>(node:23692) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'includes' of undefined
      at /home/mikkel/bots/csgo/app.js:87:24
      at &lt;anonymous&gt;
      at process._tickCallback (internal/process/next_tick.js:189:7)
  (node:23692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 13)
  </code></pre>
  
  <p>I don't know, what this error does mean since I'm noob to nodejs.</p>
  
  <p>Version, of npm/node:</p>
  
  <pre class="lang-sh prettyprint-override"><code>node: v8.16.1
  npm: 6.12.0
  </code></pre>
  
  <p>What is it that I must have changed. I have no sense of javascript or nodejs. the script lay freely on GitHub.</p>
  
  <p><strong>Update: edited 10/10/2019 - 15:28</strong>:
  What with date format? - Example; on the github, it reading from check-update.txt with this format: 10/23/2018 (e.g)</p>
  
  <p>Seems it doesn't post for me on Discord. (which it should do if it doesn't do it)</p>
  
  <p>Example:</p>
  
  <pre><code>    // Checking every 10 seconds if there's a new update, and if it's been posted already
      setInterval(getUpdate, 10000);
  </code></pre>
  
  <p>Here is the problem:</p>
  
  <pre><code>            // Do nothing if update has been posted already.
          }
      })();
  }
  </code></pre>
  
  <p>Maybe I should create a new bot from discord developers?</p>