{"id":18045,"library":"node-file-cache","title":"Simple File-Based Cache","description":"node-file-cache is a straightforward, file-based caching module for Node.js, currently at version 1.0.2. It leverages `lowdb` for persistent storage, allowing developers to store key-value pairs with optional lifespans and tags for granular expiry. Its design emphasizes simplicity over advanced features or high-throughput performance. Given its age and the explicit mention of Node.js 4.4.5 as a minimum requirement (a version from 2016), it appears to be an unmaintained package with an irregular or non-existent release cadence. It's best suited for small-scale applications where a simple, durable, local cache is sufficient and high concurrency or complex cache invalidation strategies are not required.","status":"abandoned","version":"1.0.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install node-file-cache","lang":"bash","label":"npm"},{"cmd":"yarn add node-file-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-file-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as the underlying file storage wrapper for persistence.","package":"lowdb","optional":false}],"imports":[{"note":"The module exports a `create` factory function directly from the `require` call. It does not support ES modules.","wrong":"import { create } from 'node-file-cache'; // Not supported, CommonJS only","symbol":"create","correct":"const cache = require('node-file-cache').create();"},{"note":"Configuration options are passed directly to the `create` factory function upon instantiation.","wrong":"const { create } = require('node-file-cache')(); // Incorrect destructuring and invocation, `create` is a function itself","symbol":"createWithOptions","correct":"const cache = require('node-file-cache').create({ file: 'my-cache.json', life: 7200 });"},{"note":"The `require` call itself does not return the cache instance; you must call the `create()` method on the result.","wrong":"const cache = require('node-file-cache');\ncache.set('key', 'value'); // Missing the .create() invocation to get an instance","symbol":"CacheInstance","correct":"const cache = require('node-file-cache').create();\ncache.set('key', 'value');"}],"quickstart":{"code":"const cache = require('node-file-cache').create(); // default configuration\n\nconst key = 'my-cache-key';\nconst item = {\n    name: 'my cache item'\n};\nconst options = {\n    life: 60,   // set lifespan of one minute\n    tags: [ 'my-cache-tag', 'another-tag' ]\n};\n\ncache.set(key, item, options);\n\nconst cachedItem = cache.get(key); // depending on context this can either return cached data or null\n\nif (cachedItem) {\n    console.log(`Cached item: ${cachedItem.name}`);\n}\n\n// To demonstrate removal\nsetTimeout(() => {\n    cache.expire(key); // removes item with particular key\n    console.log(`Cache size after expiry: ${cache.size()}`);\n}, 1000); // Wait a bit to ensure async operation completes and cache is still there before expiry","lang":"javascript","description":"Demonstrates initializing the cache, setting a record with options (lifespan, tags), retrieving it, and then explicitly expiring it by key."},"warnings":[{"fix":"Upgrade Node.js to at least version 4.4.5. However, due to the package's age, it's recommended to use a modern caching solution for current Node.js applications.","message":"The module explicitly requires Node.js version 4.4.5 or higher due to its use of ES6 features. Running it on significantly older Node.js versions will result in syntax errors.","severity":"breaking","affected_versions":"<4.4.5"},{"fix":"Evaluate modern, actively maintained caching libraries (e.g., `node-cache`, `cache-manager`, `ioredis` for Redis-based) for new projects or when migrating existing applications.","message":"This package appears to be unmaintained. The README states 'Since the github repository is not ready yet', implying it was never actively hosted or updated for a long period. This means no bug fixes, security patches, or compatibility updates for newer Node.js versions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For high-performance or concurrent caching needs, consider in-memory caches or external cache services like Redis or Memcached.","message":"Being a file-based cache using `lowdb`, `node-file-cache` may not be suitable for high-concurrency environments or applications requiring high performance. Concurrent writes could lead to race conditions, data corruption, or significant I/O bottlenecks.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `const cache = require('node-file-cache').create();` to import and instantiate the cache module.","message":"The package only supports CommonJS `require()` syntax. Attempting to import it using ES module `import` statements will result in runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const cache = require('node-file-cache').create();`","cause":"Attempting to use ES module `import` syntax (`import { create } from 'node-file-cache';`) with this CommonJS-only package.","error":"TypeError: (0, _nodeFileCache.create) is not a function"},{"fix":"This package is not compatible with pure ES module environments. You would either need to transpile your code, convert your project to CommonJS, or use a different caching library that supports ES modules.","cause":"Attempting to use `require()` in an ES module context (`'type': 'module'` in package.json or `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Run `npm install node-file-cache --save` in your project directory.","cause":"The package `node-file-cache` has not been installed or is not resolvable from the current working directory.","error":"Error: Cannot find module 'node-file-cache'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}