I tried using other api and it worked, however it does not work with this one.
const express = require("express");
const https = require("https");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.get("/",(req, res)=>{
https.get("https://pixabay.com/api/?key=xxx-zzz&q=yellow+flowers&image_type=photo", (response)=>{
console.log(response.statusCode);
response.on("data",d=>{
const lala = JSON.parse(d);
console.log(lala);
})
})
});
app.listen(3000,()=>{
console.log("Server started on port 3000")
})
I got this in the console
200
undefined:1
{"total":28739,"totalHits":500,"hits":[{"id":3063284,"pageURL":"https://pixabay.com/photos/rose-flower-petal-floral-noble-3063284/","type":"photo","tags":"rose, flower, petal","previewURL":"https://cdn.pixabay.com/photo/2018/01/05/16/24/rose-3063284_150.jpg","previewWidth":150,"previewHeight":99,"webformatURL":"https://pixabaSyntaxError: Unexpected end of JSON input
at JSON.parse ()
console.log()that you don't show in the snippet? Where isundefined:1coming from?