Back

how do I use res.send() from a function

  • 0
  • Functions
  • Web
mr.nobody4704
23 Feb, 2024, 17:52

I'm working on a web app with cloud functions. I encountered an error when I used return res.send() from a function, like function trigger() { return res.send() //when everything is done }

But i encountered an error, i'm not able to use it from a function, but I can use it directly. Can anyone help me with this error ? I'm working with node js

TL;DR
Developers are having trouble using `res.send()` from a function in their web app with cloud functions. The solution provided is to change `trigger()` to `return trigger()` in order for the nested return to propagate.
Meldiron
23 Feb, 2024, 17:53

Heyy 👋 Could you share more of your function? Its hard to guess from above example. Also, could you share what error exactly you are facing?

mr.nobody4704
23 Feb, 2024, 17:54

I'm facing an error which shows me to set context.res.empty() if there is an empty response.

mr.nobody4704
23 Feb, 2024, 17:56

Like I can do this

if (req.method === "POST") { return res.send("Hey !", 200); }

But I can't do this

` if (req.method === "POST") { function trigger() { return res.send("Hey ! Function", 200); }

trigger(); } `

Meldiron
23 Feb, 2024, 17:57

Ah, I see, you will need to change trigger() to return trigger().

If you return in nested function, it doesnt automatically propagate as return of the root function.

mr.nobody4704
23 Feb, 2024, 17:57

thanks bud, if I face any issues further I will surely reach out to you !

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more