Hello, I am trying to make a thing where every minute node-fetch would do what I want, I already have that whole thing in place but, how would I make it so it would detect if something has changed because I don’t want it to send the same thing if nothing has changed… Also, how would I make the code wait so it isn’t constantly running? Can anybody help?
Can you explain what sort of trigger you want? For example, a local file has changed content, or you press a button on a web page?
Possibly you’re thinking of a listener which triggers code events? Like in hello-express, the default node express glitch project?
You might be interested in setInterval, https://nodejs.org/dist/latest-v12.x/docs/api/timers.html
Every minute the function would go through again, that’s the trigger.
What sort of condition to be detected?
Node-Fetch will fetch a link and if the data is changed I want it to send a message but if it isn’t changed then it will do nothing.
To keep the app awake for its polling via node-fetch, on Glitch you’d need it to be a boosted (paid) app, see https://glitch.com/pricing
Suggested app ingredients:
- https://glitch.com/~hello-express for a web listener to be persistent
- https://glitch.com/~starter-discord/ for the discord messaging (someone with more recent discord bot experience might advise a better link)
https://www.npmjs.com/package/nedb or a similar easy to use database, for storing the last known result to compare with; store the database in a file in a
.datadirectory to avoid the data being automatically versioned by git
- node-fetch as you mentioned
After the app has connected to its database, setup a timer with
setTimer to do the fetch and comparison and messaging.