Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
That doesn't sound like the right way to go about things if netlify functions are the same as AWS and Googles
thats like trying to invoke an express function inside of an express function
so the thing i want to do is like to chain cloud functions to make a combined function
so first why do you want to do such, and 2nd what are you getting right now that prevents it from working?
Why not call 1 netlify function and call normal functions in it?
and those normal functions can chain
normal function as in function running in the frontend?
Like your writing JS right?
The only "netlify function" part that is strict is the execution environment and the exposed function you pass to exports.handler. Pass that just create other JS functions to call inside of that function, which should give what you want
const fetchAllProducts = async () => {
    const categories = await GetActiveCategories();
    const categoriesIdArray = categories.map(category => category.CategoryId);
   const productsNested = await Promise.all(categoriesIdArray.map(categoryID => getSearchResults(' ', categoryID)));
   return ProductsNested.flat()

const hotDeals = async () => {
    const products = await fetchAllProducts();
    return products.filter(product => product.DiscountPercentage > 15)

my lambda is to implement this functionality, the idea is to have one lambda that does a fetch of active categories, and then the next lambda get this data to calls the getSearchResults lambda to return a list of all products.

since we write normal javascript in a way that has seperate functions for each specific task, in a lambda are we supposed to not follow that pattern and write a big function that does everything in it?

to leverage lambda/cloud functions you just need to provide 1 function "publically" so netlify can call it, and pass in the arguments, past that it usually doesn't care except that you "respond" somehow. Just like express you can write whatever you want within the handler, how-ever you want to handle it
@brad sorry i didn't understand that, this is what i tried doing
import fetch from 'node-fetch';
const {API_TOKEN} = process.env;

exports.handler = async (event,context,callback) => {

    const activeCategories = await fetch('/.netlify/functions/getActiveCategories')

    const categoriesIdArray = categories.map(category => category.CategoryId);
    const productsNested = await Promise.all(categoriesIdArray.map(categoryID => getSearchResults(' ', categoryID)));
        statusCode: 200,
        body: JSON.stringify(const productsNested)

I also tried doing 

import getActiveCategories from './getActiveCategories';
and then 
const activeCategories = await getActiveCategories()
so what doesn't work with what your doing?
Oh your trying to make an http request to another function
you need to call it using fetch as if your calling it from the front-end. Or seperate out the logic in the getActiveCateogires to an actual function and cal it like your last example
but that only works if the server knows what function your talking about
import fetch from 'node-fetch';
const {API_TOKEN} = process.env;

exports.handler = async (event,context,callback) => {

    const activeCategoriesRes = await fetch('https://api.example.com/category/GetActiveCategories',{
        method: 'GET',
        headers: {'APIToken': API_TOKEN}
    const activeCategoriesData = await activeCategoriesRes.json();
    const categories = activeCategoriesData.result;
    const categoriesIdArray = categories.map(category => category.CategoryId);
    const productsNested = await Promise.all(categoriesIdArray.map(categoryID => {
        const categoryProductsRes = await fetch(`http://api.example.com/Product/GetProductSearchByCategory`,{
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'APIToken': API_TOKEN
        body: JSON.stringify({
            "CategoryID": CategoryID,
            "Search": " ",
            "lstBrand": [],
            "lstColor": [],
            "lstSize": [],
            "PriceFrom": 0,
            "PriceTo": 0,
            "MaxPrice": 0,
            "Page": 1,
            "Show": 9999,
            "UserID": ""
    const categoryProductsData = await categoryProductsRes.json();
    return categoryProductsData.result;
    const productsList =  productsNested.flat();
    const hotDeals = productsList.filter(product => product.DiscountPercentage > 15 && product.SellingPrice > 50);

        statusCode: 200,
        body: JSON.stringify(hotDeals)
since i have separate lambdas that already do getActiveCategories and getSearchResults, this seems like duplication of code
You can share the code if you put the logic into a common function outside of the files. You will end up needing a build system tho
otherwise you will have to call the function using fetch correctly
I'd recommend reading into both approaches. The sharing code approach is more complex in terms of setting up, but will be more performant and scalable for development
@bradtaniguchi sorry I'm not knowledgeable enough to understand the approaches you are referring to, could you send me link or something that i can read which describes the approaches you mentioned
@siliconchild So first of all, I point out stuff for you to go out and research yourself. Googling something as simple as "how to have multiple functions for a cloud function" is a good start. The other approach using fetch could be looked into as "how to use fetch in nodejs"
I don't suggest believing you need any more guidance than that most of the time. If you don't know what concepts i'm talking about then it sounds like its time to first figure out what I'm talking about (by getting more familiar in any way possible) and then learn how you can apply it in your own project
Same goes for your errors. I'm sure you will figure it out after some time, but don't expect to be able to run code, figure stuff out without trouble, that isn't the point. The point is being presented a problem and being able to figure it out over time. Google your way out of your error, bash your head against the code, and learn through trial error and understanding. That is how you get experience

that it periodically fetches data from the original server, say once every 2 hours and then caches it

The netlify server instance shouldn't stay running longer than a few seconds, or minutes after each call between calls. Thus you will need something running "long term" if you want to cache it for 2 hours

Hello Fellow Campers. I am looking for FE Campers to join a project on which I am working on. I recently participated in a hackathon and WON in it. Now I am being requested to develop it further and superfast. Will be glad to get any of the Fellow Campers to test out the skills that we have acquired through FCC onto a real life product. Here is a link to the blog post mentioning about my team wining the hackathon https://blog.kyber.network/kyberdefi-hackathon-meet-the-winners-bea5bc9ec983 . Drop me a dm if you would like to come work on this.