title: how to pass API key from env variable in netlify function
body: <p>I'm trying to host a fullstack react project on netlify and im using a netlify function for my express backend but im unsure how to pass my API key in this netlify function im making. <br><br>
  The console.log error: Uncaught (in promise) SyntaxError: Unexpected token &lt; in JSON at position 0</p>
  <p>This is my netlify lambda function:<br></p>
  <pre><code>const fetch = require(&quot;node-fetch&quot;);
  require('dotenv').config();
  
  exports.handler = async (event, context) =&gt; {
      const term = event.queryStringParameters.term;
      const location = event.queryStringParameters.location
      const targetURL = `https://api.yelp.com/v3/businesses/search?term=${term}&amp;location=${location}`;
  
      try {
          const response = await fetch(targetURL);
          const data = await response.json();
          return {
              statusCode: 200,
              body: JSON.stringify({ data }),
              api: process.env.APIKEY
          };
      } catch (error) {
          console.log(error);
          return {
              statusCode: 500,
              body: JSON.stringify({ error: 'Failed fetching data' }),
          };
      }
  };
  </code></pre>
  <p>This was my server during devlopment:<br></p>
  <pre><code>const express = require('express');
  const axios = require('axios');
  require('dotenv').config();
  const cors = require('cors');
  const bodyParser = require('body-parser');
  
  const app = express();
  app.use(cors());
  const port = process.env.PORT || 2000;
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  const apiKey = process.env.APIKEY
  
  app.get('/api/hello', (req, res) =&gt; {
      const { term, location } = req.query
      const config = {
          method: 'get',
          url: `https://api.yelp.com/v3/businesses/search?term=${term}&amp;location=${location}`,
          headers: {
              'Authorization': `Bearer ${apiKey}`
          }
      };
  
      axios(config)
          .then(function (response) {
              return JSON.stringify(response.data, null, 2)
          })
          .then(function (jsonResponse) {
              res.send(jsonResponse)
          })
          .catch(function (error) {
              console.log(error);
          });
  });
  
  app.listen(port, () =&gt; console.log(`Listening on port ${port}`)); 
  </code></pre>
  <p>The new API call:<br></p>
  <pre><code>    const { default: SearchBar } = require(&quot;../../components/SearchBar/SearchBar&quot;);
      let serverURL;
      
      const Yelp = {
          searchYelp(term, location) {
              return fetch(`./netlify/functions/business-get?term=${term}&amp;location=${location}`)
                  .then((response) =&gt; {
                      // console.log(response)
                      return response.json()
                  }).then((jsonResponse) =&gt; {
                      serverURL = jsonResponse.api
                      // console.log(jsonResponse)
                      if (jsonResponse.businesses) {
                          return jsonResponse.businesses.map((business) =&gt; {
                              return {
                                  id: business.id,
                                  imageSrc: business.image_url,
                                  name: business.name,
                                  address: business.location.address1,
                                  city: business.location.city,
                                  state: business.location.state,
                                  zipCode: business.location.zip_code,
                                  category: business.categories.title,
                                  rating: business.rating,
                                  reviewCount: business.review_count,
                              }
                          })
                      }
                  })
          }
      }
      
      export default Yelp;
  </code></pre>