Registry / database / dirty-compact

dirty-compact

JSON →
library0.0.2jsnpmunverified

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.

npm install dirty-compact
INSTALL
IMPORT
SIG · DIRTY-COMPACT
D
dirty-compact
databasejavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compact
const compact = require('dirty-compact').compact;
import { compact } from 'dirty-compact';
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.
default
const dirtyCompact = require('dirty-compact'); const compact = dirtyCompact.compact;
import dirtyCompact from 'dirty-compact';
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`.

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.

const fs = require('fs'); const path = require('path'); // Create a dummy dirty database file for demonstration const dbPath = path.join(__dirname, 'database.db'); const bakPath = path.join(__dirname, 'database.db.bak'); const dummyData = [ { key: 'user1', value: { name: 'Alice', age: 30 } }, { key: 'user2', value: { name: 'Bob', age: 25 } }, { key: 'user1', value: { name: 'Alice', age: 31 } }, // Overwritten, will be compacted { key: 'user3', value: { name: 'Charlie', age: 35 } } ].map(entry => JSON.stringify(entry)).join('\n') + '\n'; fs.writeFileSync(dbPath, dummyData); console.log('Created dummy database for compaction.'); // Import and use dirty-compact const compact = require('dirty-compact').compact; compact(dbPath, bakPath, function (err) { if (err) { console.error('Compaction failed:', err); // Clean up dummy files on error for retry if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath); if (fs.existsSync(bakPath)) fs.unlinkSync(bakPath); return; } console.log('Success! Database compacted.'); // Verify compacted content (user1 should only appear once) const compactedContent = fs.readFileSync(dbPath, 'utf8'); console.log('Compacted DB content:\n', compactedContent); // Clean up dummy files after demonstration if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath); if (fs.existsSync(bakPath)) fs.unlinkSync(bakPath); console.log('Cleaned up dummy files.'); });
Debug
Known issues
breakingThis 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.
fix
Avoid using this package for new projects. Consider modern, actively maintained alternatives for key-value storage or flat-file databases.
affects: >=0.0.2
breakingThe 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.
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.
affects: >=0.0.2
gotchaDue 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.
fix
Do not use in production environments. If absolutely necessary for legacy systems, isolate it heavily and consider alternatives for data storage.
affects: >=0.0.2
gotchaThe 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.
fix
Evaluate your data storage needs. For more than ~1 million records, or for any production use, choose a robust, actively maintained database solution.
affects: >=0.0.2
gotchaWorking 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.
fix
Always back up your database files before running any compaction. Implement robust error handling and verification steps if this package must be used.
affects: >=0.0.2
Errors
Common errors & fixes
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
Attempted to `import` `dirty-compact` in an ES module context, but the package only provides CommonJS exports.
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).
TypeError: compact is not a function
The `compact` function was not correctly destructuring or accessing the module export, likely due to a mistaken default import or incorrect property access.
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;`.
Error: EACCES: permission denied, open './database.db'
The Node.js process does not have sufficient read/write permissions for the database file or the directory it resides in.
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.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
dirtyrequiredThis package is a utility specifically for the node-dirty database. node-dirty is also abandoned.
Agent activity
7 hits · last 30 days
node
6
Resources
dirty-compact — npm install dirty-compact · libregistry