const fs = require('fs');
const {promisify} = require('util');

const stat = promisify(fs.stat);

const checkCacheExpiry = (path, ttl) =>
    stat(path).then(({mtime}) => {

        if (new Date(mtime).getTime() + ttl < Date.now()) {

            throw new Error('Cache has expired.');

        }

    });

module.exports = checkCacheExpiry;

const fs = require('fs');
const {promisify} = require('util');

const stat = promisify(fs.stat);

const checkCacheExpiry = (path, ttl) =>
    stat(path).then(stats => {

        if (new Date(stats.mtime).getTime() + ttl < Date.now()) {

            throw new Error('Cache has expired.');

        }

        return stats;

    });

module.exports = checkCacheExpiry;

Return stats object when checking for expiry.
Return stats object when checking for expiry.
