javascript - TypeError: res.json is not a function

javascript – TypeError: res.json is not a function

javascript – TypeError: res.json is not a function

Because youre overwriting your res variable in the .then of your rp function:

app.post(/danger, function response(req, res) { //see, res here was being overwritten
   ..
   ..
   rp(option).then(function(response) { //change the variable name of res to response (or turtles, who cares, just dont overwrite your up most res)

.json isnt a function. Unless you are using a library that makes it one, JavaScript uses JSON (with two methods .parse() and .stringify() one of which you use in the line above).

If you are trying to set an object property by the name of .json then it would be:

res.json = {data: [res, dangerRate]};

javascript – TypeError: res.json is not a function

With new httpClient libary, you dont need to call .json() method, Just use this simple map instead of the json method.

.map(res => res );

Related posts on JavaScript  :

Leave a Reply

Your email address will not be published.