Skip to content
Advertisement

Res.send not a function

I have an endpoint (using express) which requires me to do some fetching first. Once a parse the response and use res.send I get an error res.send is not a function.

I tried searching for this error but all searches show users had res,req in the wrong order. In this case, mine appear to be right.

Why is it res is not scope after a convert my response to JSON?

JavaScript

Advertisement

Answer

Your outer response variable is overwritten by your inner result variable. JS goes from the inner most scope to outer most looking for variable. Since, res is already defined in the then clause, that res is used.

Changing it to resp should work.

JavaScript

You probably want to send something in the catch part too.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement