npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cron-file-cleaner

v1.1.0

Published

Remove old files periodically

Readme

cron-file-cleaner

cron-file-cleaner is a nodejs module for removing old files periodically.

Build Status Coverage Status Code Climate Dependency Status

Install

npm install cron-file-cleaner

Basic example

A basic example can look like this:

var FileCleaner = require('cron-file-cleaner').FileCleaner;

var fileWatcher = new FileCleaner('/path/to/folder/', 600000,  '* */15 * * * *', {
  start: true
});

This would scan the directory /path/to/folder/ every 15 minutes and deletes every containing file that is older than 10 minutes (= 600000 milliseconds).

Usage

cron-file-cleaner scans a given folder periodically and deletes all files that are older than the given threshold. The interval for scanning the folder can be set with a crontab syntax.

var FileCleaner = require('cron-file-cleaner').FileCleaner;

var fileWatcher = new FileCleaner(path, threshold, interval, options);

The parameters are:

  • path: The full path to the folder to watch [REQUIRED]
  • threshold: Threshold in milliseconds. Every file that is older will be deleted [REQUIRED]
  • interval: The interval for scanning the folder given in a crontab syntax, e.g. '* 00 * * * *' [REQUIRED]
  • options: A JSON object with additional options. [OPTIONAL]

The options object can have the following attributes:

  • start: Boolean, default is false. In that case you must use fileWatcher.start()
  • recursive: Boolean, default is false. If true it scans the folder recursively.
  • timeField: Which time field of the files should be considered. Default 'atime', can be 'atime', 'ctime, or 'mtime'.
  • timeZone: Timezone to use, default is undefined, e.g. 'America/Los_Angeles'.
  • blackList: A RegEx for excluding files, default is undefined, e.g. /\.gitkeep/
  • whitList: A RegEx for including only the files with a matching name, default is undefined, e.g. /.*\.log/

Methods

If you don't set the option start to true, you need to start the process explicitly with

fileWatcher.start();

To stop the process, just run

fileWatcher.stop();

If you want to start a scan immediately ignoring the given interval you can run

fileWatcher.cleanUp();

Events

You can listen to the following events (see full example above):

  • start: Will be triggered on starting the process
  • stop: Will be triggered on stopping the process
  • delete: Will be triggered on deleting a file
  • error: Will be triggered if an error occurs

Full example

var FileCleaner = require('cron-file-cleaner').FileCleaner;

var tmpWatcher = new FileCleaner(__dirname + '/tmp_files/', 60 * 60 * 1000,  '00 */15 * * * *', {
  recursive: true,
  timeField: 'ctime'
});

tmpWatcher.on('delete', function(file){
  console.log('DELETE');
  console.log(file.name); //Name of the file
  console.log(file.folder); //folder path
  console.log(file.path); //Full path of the file
});

tmpWatcher.on('error', function(err){
  console.log('ERROR');
  console.error(err);
});

tmpWatcher.on('stop', function(info){
  console.log('STOP');
  console.log(info.path);
  console.log(info.cronTime);
});

tmpWatcher.on('start', function(info){
  console.log('START');
  console.log(info.path);
  console.log(info.cronTime);
});

tmpWatcher.start();

Tests

npm test

Coverage

npm run coverage

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add tests for any new or changed functionality. Lint and test your code.

License

MIT