Easily give your files a max lifetime.
npm i expire-fs
{String}
folder - folder to watch{RegExp|function(String,Stats):Boolean=}
filter=/.*/
- files to filter{String=}
timeType='birthtime'
- type of time- possible values
['atime', 'mtime', 'ctime', 'birthtime']
- possible values
{Number=}
expire=Infinity
- time in milliseconds of max file life{Number=}
pressure=1.0
- percentage of maximum disk usage before starting to delete files before they expire{Number=}
interval=300000
- time in milliseconds between searching cycles{Boolean=}
autoStart=true
- auto start the timer{Boolean=}
removeEmptyDirs=false
- remove any dir that is empty{Boolean=}
removeCleanedDirs=true
- remove dir only if it was cleaned by expire-fs
Method that will run the clean routine on demand
Method to start the timer. If already started, request is ignored.
Method to stop the timer. If already stopped, request is ignored.
Event fired when a clear cycle has finished
Event fired when an error occurs during a schedules clear cycle.
const ExpireFs = require('expire-fs');
const ex = new ExpireFs({
// clean folder
folder: '/tmp/upload_segments',
// using filter
filter: /\.segment\.\d+$/,
// start deleting oldest files if disk usage is above 80%
pressure: 0.8,
// delete files after one day
expire: 24 * 3600 * 1000
});
// event fired one a .clear cycle is completed
ex.on('clean', () => console.log('done cleanning');
// fire a manual clean
ex.clean().then(() => console.log('done'), console.error);