Simple question, I want to set 24 or 12 hours timeout in Node.js to periodically (once or twice a day) check some db data and clean suspicious garbage, if any.
I've had success using the package cron. It's simple to use and is generally compatible with a CronTab. I've had a job that runs once a month and this has worked consistently since last year, so I can attest to it.
That being said, this package ultimately does just use setTimeout internally so there's no real issue with you doing that. If your timeout number is too large (larger than the maximum JavaScript integer) there may be a problem, but 1000 * 60 * 60 * 24 is significantly smaller than that.
Obviously if your system goes down or the script crashes for some other reason the timeout won't work.
You could also just use crontab directly if it's available (or Windows task scheduling).