I'm trying to send two json but It doesn't work. It prints TypeError: res.json is not a function
but I don't get why It happens. Is there any ideas? Thank you !!
app.post('/danger', function response(req, res) {
let placeId = req.body.data;
let option = {
uri: 'https://maps.googleapis.com/maps/api/directions/json?',
qs: {
origin:`place_id:${placeId[0]}`, destination: `place_id:${placeId[1]}`,
language: 'en', mode: 'walking', alternatives: true, key: APIKey
}
};
rp(option)
.then(function(res) {
let dangerRate = dangerTest(JSON.parse(res), riskGrid);
res.json({ data: [res, dangerRate]});
})
.catch(function(err) {
console.error("Failed to get JSON from Google API", err);
})
});
I got this error message because I had the arguments in the wrong order in the handler method. (amateur's fault)
Wrong order: (res, req)
app.get('/json', (res, req) => {
res.json({
"message": "Hello json"
});
});
Right order: (req, res)
app.get('/json', (req, res) => {
res.json({
"message": "Hello json"
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With