title: How do I make this axios call inside my own API route?
body: <p>This is my first time trying to make an API call to a third party while inside my own API route. The following code does not work because I get the error &quot;Cannot use import statement outside a module.&quot; This code is called by a thunk at the front end.</p>
  <p>If I can't import axios, what's an alternative?</p>
  <p>EDIT: I got rid of the error by doing 'const axios = require('axios') but now the results I'm getting is undefined.</p>
  <p>EDIT2: Resolved. Through use of the following:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>router.get("/:zip", async (req, res, next) =&gt; {
    try {
      let data = [];
      await axios
        .get(`https://api.yelp.com/v3/businesses/search`, {
          headers: {
            Authorization: `Bearer ${process.env.SECRET_KEY_YELP}`,
          },
          params: {
            location: req.params.zip,
            //   categories: "coffee",
          },
        })
        .then((response) =&gt; {
          data = response.data;
        });
      res.send(data);
    } catch (err) {
      next(err);
    }
  });</code></pre>
  </div>
  </div>
  </p>
  <p>ORIGINAL CODE WITH ISSUE:
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>const router = require("express").Router();
  module.exports = router;
  import axios from "axios";
  router.get("/:zip", async (req, res, next) =&gt; {
    try {
      //const restaurants = await Test.findAll({})
      const result = await axios.get(
        `https://api.yelp.com/v3/businesses/search?location=${req.params.zip}`,
        {
          headers: {
            Authorization: `Bearer ${process.env.SECRET_KEY_YELP}`,
          },
          params: {
            categories: "coffee",
          },
        }
      ).data;
      res.send(result);
    } catch (err) {
      next(err);
    }
  });</code></pre>
  </div>
  </div>
  </p>