I have a ExpressJS API set up to service requests from the front end, connecting it to my Redis Database. One endpoint takes in a parameter specified in the request URL(GET request), and returns a number. When I use Axios or Node-Fetch to hit this endpoint, it returns null, which is what Node-Redis returns if the key does not exist. When I hit this endpoint with cURL and Chrome, it returns the correct number. Other endpoints function correctly. Why is this?
Server Code:
router.get("/api/:id/bal", async (req, res) => {
let id = req.params.id;
await client.get(id, (err, response) => {
if (err) throw err;
res.send(response);
});
});
Axios call:
axios.get(`http://localhost:4000/api/${id}/bal`)
.then((response) => {
console.log(response.data);
})
cURL call:
curl http://localhost:4000/api/id/bal -i
(in both id is replaced by a real account id)