In Node, delete all files older than an hour?

I’ve used find-remove for a similar usecase.

According to the documentation and what you are trying to do, the code will be:

var findRemoveSync = require('find-remove');
findRemoveSync(__dirname + '/uploads', {age: {seconds: 3600}});

I’m actually running that every 6 minutes and deleting files older than 1 hour by doing:

setInterval(findRemoveSync.bind(this,__dirname + '/uploads', {age: {seconds: 3600}}), 360000)

See this example on how I’m using find-remove to cleanup the /uploads folder.

Leave a Comment