{"id":17578,"library":"dirty-compact","title":"Dirty Compact","description":"dirty-compact is a utility package designed to compact databases created by node-dirty, a flat-file, newline-separated JSON key-value store. Last published over 12 years ago at version 0.0.2, it is tightly coupled with node-dirty, which itself has seen no updates since 2014. Both packages are long-abandoned, meaning they receive no active development, bug fixes, or security patches. They were intended for small-scale applications, typically under 1 million records, and lack modern features like ES module support, TypeScript types, or robust error handling. Due to their age and unmaintained status, they are highly susceptible to compatibility issues with current Node.js versions and present significant security vulnerabilities.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/beaugunderson/node-dirty-compact","tags":["javascript","dirty","compact"],"install":[{"cmd":"npm install dirty-compact","lang":"bash","label":"npm"},{"cmd":"yarn add dirty-compact","lang":"bash","label":"yarn"},{"cmd":"pnpm add dirty-compact","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a utility specifically for the node-dirty database. node-dirty is also abandoned.","package":"dirty","optional":false}],"imports":[{"note":"The package only supports CommonJS `require()`. It does not provide ES module exports. Attempting to use `import` will result in an `ERR_REQUIRE_ESM` error on recent Node.js versions.","wrong":"import { compact } from 'dirty-compact';","symbol":"compact","correct":"const compact = require('dirty-compact').compact;"},{"note":"While technically correct to import the entire module, the primary function `compact` is exported as a named property. Default imports are not supported with CommonJS `require`.","wrong":"import dirtyCompact from 'dirty-compact';","symbol":"default","correct":"const dirtyCompact = require('dirty-compact');\nconst compact = dirtyCompact.compact;"}],"quickstart":{"code":"const fs = require('fs');\nconst path = require('path');\n\n// Create a dummy dirty database file for demonstration\nconst dbPath = path.join(__dirname, 'database.db');\nconst bakPath = path.join(__dirname, 'database.db.bak');\n\nconst dummyData = [\n  { key: 'user1', value: { name: 'Alice', age: 30 } },\n  { key: 'user2', value: { name: 'Bob', age: 25 } },\n  { key: 'user1', value: { name: 'Alice', age: 31 } }, // Overwritten, will be compacted\n  { key: 'user3', value: { name: 'Charlie', age: 35 } }\n].map(entry => JSON.stringify(entry)).join('\\n') + '\\n';\n\nfs.writeFileSync(dbPath, dummyData);\nconsole.log('Created dummy database for compaction.');\n\n// Import and use dirty-compact\nconst compact = require('dirty-compact').compact;\n\ncompact(dbPath, bakPath, function (err) {\n  if (err) {\n    console.error('Compaction failed:', err);\n    // Clean up dummy files on error for retry\n    if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);\n    if (fs.existsSync(bakPath)) fs.unlinkSync(bakPath);\n    return;\n  }\n\n  console.log('Success! Database compacted.');\n  // Verify compacted content (user1 should only appear once)\n  const compactedContent = fs.readFileSync(dbPath, 'utf8');\n  console.log('Compacted DB content:\\n', compactedContent);\n\n  // Clean up dummy files after demonstration\n  if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);\n  if (fs.existsSync(bakPath)) fs.unlinkSync(bakPath);\n  console.log('Cleaned up dummy files.');\n});\n","lang":"javascript","description":"This example demonstrates how to use `dirty-compact` to compact a `node-dirty` database file. It first creates a simple dummy database with some overwritten entries and then uses the `compact` function to optimize it, removing redundant data and saving the original as a backup. It highlights the CommonJS `require` syntax necessary for this package."},"warnings":[{"fix":"Avoid using this package for new projects. Consider modern, actively maintained alternatives for key-value storage or flat-file databases.","message":"This package, and its underlying dependency `node-dirty`, are both long-abandoned. They have not received updates or bug fixes for over a decade. Running them on modern Node.js versions is highly likely to encounter compatibility issues.","severity":"breaking","affected_versions":">=0.0.2"},{"fix":"Ensure your project is configured for CommonJS, or manually `require()` the module in an older Node.js environment. For new projects, use modern packages with ESM support.","message":"The package only supports CommonJS `require()` syntax. It does not provide ES module exports and will throw an `ERR_REQUIRE_ESM` error if used with `import` statements in an ES module context.","severity":"breaking","affected_versions":">=0.0.2"},{"fix":"Do not use in production environments. If absolutely necessary for legacy systems, isolate it heavily and consider alternatives for data storage.","message":"Due to its unmaintained status, this package is vulnerable to undiscovered security flaws. There will be no patches for any reported or future vulnerabilities, making it a significant security risk for any production application.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Evaluate your data storage needs. For more than ~1 million records, or for any production use, choose a robust, actively maintained database solution.","message":"The underlying `node-dirty` database has documented scalability limitations, performing poorly or hitting a \"hard wall\" after approximately 1 million records. This compacting utility does not bypass these inherent limitations.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Always back up your database files before running any compaction. Implement robust error handling and verification steps if this package must be used.","message":"Working with unmaintained file-based databases carries a high risk of data corruption, especially during compaction operations if not handled carefully or if unexpected errors occur. There is no ongoing support to address such issues.","severity":"gotcha","affected_versions":">=0.0.2"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const compact = require('dirty-compact').compact;` and ensure your file is treated as CommonJS (e.g., `.js` extension with `\"type\": \"commonjs\"` in `package.json`, or an older Node.js version).","cause":"Attempted to `import` `dirty-compact` in an ES module context, but the package only provides CommonJS exports.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module C:\\path\\to\\node_modules\\dirty-compact\\index.js from C:\\path\\to\\your_app\\index.js not supported. Instead change the require of index.js in C:\\path\\to\\your_app\\index.js to a dynamic import() which is also supported but an ES module file can only be loaded as an ES module"},{"fix":"Ensure you are accessing the named export `compact` correctly: `const { compact } = require('dirty-compact');` or `const dirtyCompact = require('dirty-compact'); const compact = dirtyCompact.compact;`.","cause":"The `compact` function was not correctly destructuring or accessing the module export, likely due to a mistaken default import or incorrect property access.","error":"TypeError: compact is not a function"},{"fix":"Verify that the user running the Node.js application has the necessary file system permissions (read and write) for both the source and backup database files and their containing directories.","cause":"The Node.js process does not have sufficient read/write permissions for the database file or the directory it resides in.","error":"Error: EACCES: permission denied, open './database.db'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}