Recover images from the JSON file with NodeJS

advertisements

I am testing an Electron app. I want it to grab images from this website. That website has a JSON file that has this code.

How can I get those images and put them in an img tag?

So far I have this code:

var request = require('request');

request("http://www.pgbovine.net/photos/json-files/boston.json" ,     function(error, response, body) {
body = JSON.parse(body);
console.log(body);

function addImg(arr) {
   myImg = arr[0]["filename"];
   var theImg = document.getElementById("image");

   theImg.innerHTML = myImg;
}

And this HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Pics</title>
  </head>
  <body>

    <img id="image">

    <script type="text/javascript">
      require("./memes.js")
    </script>
  </body>
</html>

The problem is, that code doesn't do anything! So how can I grab an image from the JSON file above and put it into and img tag? (Using NodeJS or vanilla JavaScript)


You are simply adding to the img tag the filename, but you need to add the entire image url not just the filename (like IMG_2914.JPG).

I tried http://www.pgbovine.net/photos/IMG_2914.JPG but got 404 error.