Skip to content
Init is coming / May 19 - 23
Back

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

  • 1
  • Functions
  • Web
mr.nobody4704
24 Feb, 2024, 07:32

I was working with my project and when everything is done, I want it to send a response to the client side just like the examples had done return res.send("done", 200, headers);

but when i do that, it says

TypeScript
Return statement missing. return context.res.empty() if no response is expected.

you can see my code here https://github.com/dev-shammi/Test/blob/main/src%2Fmain.js#L199

I also tried to use throw instead of return but it doesn't work as well. I just want it to send the response from that block of code, I have tried removing separate functions for all my code blocks and merging all into one, but that also didn't work.

TL;DR
To send a response using `res.send()` from a nested function, you can pass `res` as a parameter to the nested function. Here's an example snippet based on your code: ```javascript function myNestedFunction(res) { // Your nested logic res.send("done", 200, headers); } // Call the nested function with 'res' myNestedFunction(res); ``` This way, you can access and use `res` inside the nested function to send the response.
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