skip to Main Content

So, I need my node.js-based application to get data from some 3rd party API (Rest) every x interval and do some things with fetched data.
Let’s say, the node.js server needs to fetch some data from API every 60 seconds and make records into a database (e.g. timestamp and value). What’s the best way to make it?

Tried to search in Google but had no luck.

UPD:
Just to clarify the things: I need to achieve that functionality only using JS and Node (in my case it is SvelteKit framework over the node.js)

2

Answers


  1. Full-Stack web dev here! What I would do is install an app on my PC called XAMMP which once you start the Apache and MYSQL features, gives you a MYSQL, SQL database.
    Tutorial: https://www.youtube.com/watch?v=EN6Dx22cPRI

    As for fetching the data every sixty seconds you could use a setInterval() on the server file, and then save it to the database used by the methods in the video. I hope this helps and respond here if you have any questions.

    All you have to do past that is figure out how you want to use the API, i’m just telling you how to use the db and save the response every 60 seconds.

    Login or Signup to reply.
  2. Essentially you need to create a scheduled job in your nodejs app. You can probably make use of packages like node-cron to achieve that. It helps you provide a schedule and the function to be run on that schedule. Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search