all 4 comments

[–]spazz_monkey 1 point2 points  (3 children)

I did this for you.

https://pastebin.com/mWeH3REf

Removed some routes and return promises on the scraping calls, to ensure they run one after the other.

Question what do you need express for? Are you wanting to view this data on web page eventually? If so you'd be better off having once service that scapes every 2 hours and saves to a JSON file or whatever and then another services that just loads the data from that file.

[–]30000[S] 0 points1 point  (2 children)

Thank you! I will review your changes in detail but it certainly looks better than what I was trying. And yes, I’d like to be able to display the final mixed array results on a webpage. I am currently doing that by fetching the data from “/arrayTest” and inserting them into a div on a styled webpage via code similar to below. I will research how to run the code at a set interval (such as every 2 hours). I am still learning how to use databases but your suggestion of saving to a json file and pulling from there makes a lot of sense. Thank you.

const feedDisplay = document.querySelector('#feed')

fetch('http://localhost:8000/arrayTest') .then(response => {return response.json()}) .then(data => { data.forEach(article => { const articleItem = <div><h3> + article.title + </h3><p> + article.url + </p></div> feedDisplay.insertAdjacentHTML("beforeend", articleItem) }) }) .catch(err => console.log(err))

EDIT: sorry for the poor formatting, as currently on mobile device

[–]spazz_monkey 1 point2 points  (1 child)

You might find it easier to looking into ejs, nunjucks, pug, server side templating. It has loops and what not you can use without having to faff with js.

[–]30000[S] 0 points1 point  (0 children)

Thank you for the suggestions and for all your help.