title: App deployed on Heroku but api calls are now failing (Failed to load resource: net::ERR_CONNECTION_REFUSED, TypeError: Failed to fetch)
body: <p>My app is successfully deployed on Heroku- it works when I have VSCode open and do npm run start manually, however when I close VSCode it is no longer able to successfully call any APIs on the backend and the console shows me a bunch of errors like the one in the title.</p>
  <p>my console (ONLY happens when I close VSCode):</p>
  <p><a href="https://i.stack.imgur.com/w6Akw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w6Akw.png" alt="enter image description here" /></a></p>
  <p>my code in the backend:</p>
  <pre class="lang-js prettyprint-override"><code>const PORT = 8000
  const express = require('express')
  const cors = require('cors')
  const {TwitterApi} = require('twitter-api-v2')
  const axios = require('axios')
  const cheerio = require('cheerio')
  require('dotenv').config()
  const snoowrap = require('snoowrap')
  const linkPreviewGenerator = require('link-preview-generator')
  const spotify = require('spotify-web-api-node')
  const fetch = require('node-fetch')
  var request = require('request')
  
  const app = express()
  app.use(cors())
  
  
  app.get('/', async (req, res) =&gt; {
  
      const client = new TwitterApi(process.env.twt_bearer_token)
  
      const trendsInternational = await client.v1.trendsByPlace(1);
  
      const trendList = []
  
      for (const {trends} of trendsInternational) {
          for (const trend of trends) {
              trendList.push({
                  name: trend.name,
                  url: trend.url
              })
          }
      }
  
      res.json(trendList)
  })
  
  
  
  app.get('/reddit', async (req, res) =&gt; {
      const r = new snoowrap({
          userAgent: process.env.user_agent,
          clientId: process.env.client_id,
          clientSecret: process.env.client_secret,
          refreshToken: process.env.refresh_token
      })
  
      topPosts = []
      
      ;(await r.getHot()).forEach(post =&gt; {
          topPosts.push({
              title: post.title,
              url: post.url
          })
      })
      
      res.json(topPosts);
  
  })
  
  app.get('/news', async (req, res) =&gt; {
      const news_url = 'https://www.theguardian.com/international'
  
      axios(news_url)
      .then(response =&gt; {
          const html = response.data;
          const $ = cheerio.load(html);
          const articles = [];
          const values = new Set();
  
          $('.fc-item__title', html).each(function () { //&lt;-- cannot be a function expression
  
              const title = $(this).text().trim();
              const url = $(this).find('a').attr('href');
  
              if (!values.has(url)) {
  
                values.add(url);
  
                articles.push({
                    title,
                    url
                });
              }  
          })
          res.json(articles)
      }).catch(err =&gt; console.log(err))
  
  
  })
  
  app.listen(PORT, () =&gt; console.log(`Server is running on port ${PORT}`))```
  </code></pre>