Can't get netlify to recognize functions

Hi there, I’m having trouble getting netlify to deploy and run my functions. I created a cache warmer but netlify does seem to want to recognize it. I have the following code in a file called cacheWarmer.js in client/netlify/functions, to which it is mapped to in build configuraitons:

import axios from 'axios';

const handler = async (event, context) => {
  const fetchDatabaseIds = async () => {
    console.log("Starting to fetch database IDs...");
    
    const queryId = "#####################";
    let allDatabaseIds = [];
    let hasNextPage = true;
    let endCursor = null;

    while (hasNextPage) {
      try {
        const response = await axios.get(
          "https://########.com/graphql",
          {
            params: {
              queryId: queryId,
              variables: JSON.stringify({
                first: 50,
                after: endCursor,
              }),
            },
          }
        );

        const products = response.data.data.products;
        const productIds = products.nodes.map(product => product.databaseId);
        allDatabaseIds = [...allDatabaseIds, ...productIds];
        hasNextPage = products.pageInfo.hasNextPage;
        endCursor = products.pageInfo.endCursor;

        console.log(`Fetched ${productIds.length} databaseIds, total: ${allDatabaseIds.length}`);
      } catch (error) {
        console.error("Error fetching data:", error.message);
        break;
      }
    }
    
    return allDatabaseIds;
  };

  const fetchProductPages = async (databaseIds) => {
    const queryId = "#################";
    let productDetails = [];

    for (let databaseId of databaseIds) {
      try {
        const productUrl = `https://##################.com/graphql?queryId=${queryId}&variables=${JSON.stringify({ id: databaseId })}`;
        console.log(`Pinging product URL: ${productUrl}`);
        
        const { data } = await axios.get(productUrl);
        productDetails.push(data);
        console.log(`Fetched product data for ${databaseId}`);
      } catch (error) {
        console.error(`Error fetching data for product ${databaseId}:`, error.message);
      }
    }

    console.log("All product details fetched:", productDetails);
    return productDetails;
  };

  try {
    const databaseIds = await fetchDatabaseIds();
    const products = await fetchProductPages(databaseIds);

    return {
      statusCode: 200,
      body: JSON.stringify({ message: "Cachewarmer executed successfully", products }),
    };
  } catch (error) {
    console.error("Error in cachewarmer function:", error.message);
    return {
      statusCode: 500,
      body: JSON.stringify({ message: "Cachewarmer execution failed", error: error.message }),
    };
  }
};

export default handler;

I have a netlify toml file also in client that looks like this

[build]
command = “vite build”
publish = “dist”
base = “client”

[functions]
directory = “client/netlify/functions”
external_node_modules = [
“axios”
]
included_files = [“client/netlify/functions/**/*.js”]

[functions.“cacheWarmer”]
external_node_modules = [“axios”]
included_files = [“client/netlify/functions/cacheWarmer.js”]

Can anyone help? thanks!

if you’re specifying base here, I think you should be removing it from here (and everywhere else):

Thanks Hrishkesh.
I’ve made the change. Is there a way to monitor if the functions are firing?
I went to logs → functions and can’t see any interface that indicates it is firing.

Hi @learntocode,

You can test locally by following our docs here:

There’s also a video showing how to test locally:

Or you can add console.log() to a Netlify Serverless function, which should then display in the function logs. Function logs | Netlify Docs

You can also check the function metric log: Function Metrics | Netlify Docs