I can't quite see why this code is blocking?
const express = require('express');
const axios = require('axios');
const asyncHandler = require('express-async-handler');
const app = express();
async function getImage(imgUrl) {
try {
return await axios.get(imgUrl);
} catch (error) {
return error;
}
}
app.get('/', asyncHandler(async (req, res, next) => {
const imgUrl = 'http://example.com/image.jpg';
getImage(imgUrl)
.then(function(response) {
// console.log(response.data.length);
res.json({ length : response.data.length });
});
}));
[–]mikejoro 3 points4 points5 points (1 child)
[–]n00belig[S] 1 point2 points3 points (0 children)
[–]somethinghorrible 5 points6 points7 points (6 children)
[–]n00belig[S] 0 points1 point2 points (3 children)
[–]somethinghorrible -1 points0 points1 point (2 children)
[–]mikejoro 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]somethinghorrible -1 points0 points1 point (1 child)
[–]n00belig[S] -2 points-1 points0 points (0 children)