{"id":16324,"library":"csv-db","title":"CSV File-based Database","description":"csv-db is a lightweight, file-based database for Node.js, initially designed as a teaching aid for workshops requiring a simple data persistence layer. It stores data in plain CSV files, using newlines for row separation and semicolons for field separation. The current stable version, 0.2.2 (last published over eight years ago), relies on Promises for asynchronous CRUD (Create, Read, Update, Delete) operations, a significant evolution from its initial synchronous implementation. Its primary differentiators are extreme simplicity and direct file storage, making it suitable for minimal persistence needs, proof-of-concept applications, or educational contexts where understanding basic data storage is key. It lacks advanced database features such as indexing, complex querying, or transaction management. Due to its age and lack of updates, its release cadence is effectively nonexistent.","status":"abandoned","version":"0.2.2","language":"javascript","source_language":"en","source_url":"git://github.com/sspringer82/nodeCsvDb","tags":["javascript","csv","database"],"install":[{"cmd":"npm install csv-db","lang":"bash","label":"npm"},{"cmd":"yarn add csv-db","lang":"bash","label":"yarn"},{"cmd":"pnpm add csv-db","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and does not provide ESM exports. Use `require` for module loading.","wrong":"import CsvDb from 'csv-db';","symbol":"CsvDb","correct":"const CsvDb = require('csv-db');"},{"note":"`CsvDb` is a constructor and must be instantiated with the `new` keyword.","wrong":"const csvDb = CsvDb('input.csv', ['id', 'username']);","symbol":"CsvDb instance","correct":"const csvDb = new CsvDb('input.csv', ['id', 'username']);"}],"quickstart":{"code":"const CsvDb = require('csv-db');\nconst fs = require('fs');\n\n// Create a dummy CSV file for demonstration\nconst filePath = 'example.csv';\nconst initialData = '1;admin;secret;\\n2;user;password;';\nfs.writeFileSync(filePath, initialData);\n\nconst csvDb = new CsvDb(filePath, ['id', 'username', 'password']);\n\ncsvDb.get().then((data) => {\n  console.log('All data:', data);\n  // Expected output: [{ id: '1', username: 'admin', password: 'secret' }, { id: '2', username: 'user', password: 'password' }]\n}).catch((err) => {\n  console.error('Error fetching all data:', err);\n});\n\ncsvDb.get('1').then((data) => {\n  console.log('Data for ID 1:', data);\n  // Expected output: [{ id: '1', username: 'admin', password: 'secret' }]\n}).catch((err) => {\n  console.error('Error fetching data by ID:', err);\n});\n\n// Clean up the dummy file\nprocess.on('exit', () => {\n  if (fs.existsSync(filePath)) {\n    fs.unlinkSync(filePath);\n    console.log(`Cleaned up ${filePath}`);\n  }\n});","lang":"javascript","description":"Demonstrates initializing `csv-db` with a file and column names, then fetching all records and a specific record by ID."},"warnings":[{"fix":"Rewrite data access operations to use Promises (e.g., `.then()`/`.catch()` or `async/await`).","message":"The package transitioned from a synchronous API in its earliest versions to an asynchronous, Promise-based API. Code written for the synchronous version will break if run against version 0.2.2.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Avoid using this package for new projects or production environments where security, stability, or modern language features are important. Consider actively maintained alternatives like `csv` or `fast-csv` for parsing/writing, combined with a more robust data storage solution.","message":"This package has been abandoned for over eight years (last update v0.2.2). It is not actively maintained, may contain unpatched vulnerabilities, and does not support modern JavaScript features like ESM.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Only use this package in single-threaded, single-process applications, or where write concurrency is strictly managed externally. Do not use for high-concurrency or mission-critical applications.","message":"As a file-based database, `csv-db` offers no inherent concurrency control, locking mechanisms, or ACID properties. Concurrent write operations from multiple processes or even multiple asynchronous operations within the same process can lead to data corruption or loss.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Ensure all input CSV files are formatted with semicolons as field separators or manually parse the CSV and feed structured data to the `insert`/`update` methods.","message":"The package uses semicolons (`;`) as the default field separator. Using a comma-separated (`,`) CSV file will result in incorrect parsing.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"When updating, first `get` the existing record, merge the changes, then pass the complete merged object to `update`.","message":"The `update` method requires passing an object containing *all* field values for the row, not just the changed ones. Omitting fields will overwrite them with `undefined` or empty strings in the CSV.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using CommonJS `const CsvDb = require('csv-db');` and instantiating with `new CsvDb(...)`.","cause":"Attempting to use `CsvDb` as a function or importing it incorrectly in an ESM context.","error":"TypeError: CsvDb is not a constructor"},{"fix":"Verify the file path is correct and the Node.js process has read/write permissions for the file and directory.","cause":"The specified CSV file path does not exist or is inaccessible.","error":"Error: ENOENT: no such file or directory, open 'your-file.csv'"},{"fix":"Always chain a `.catch(err => console.error(err))` to `csv-db` promise calls or use `try/catch` with `async/await` to handle potential errors.","cause":"An error occurred during a `csv-db` operation (e.g., file I/O), but the promise's `.catch()` method or second callback argument was not used.","error":"UnhandledPromiseRejectionWarning: Unhandled promise rejection."},{"fix":"Ensure the CSV file uses semicolons as delimiters. If providing column names in the constructor, make sure they match the order and number of fields in the CSV.","cause":"The CSV file is not formatted with semicolons (`;`) as field separators, or headers do not match.","error":"Data appears corrupted or incorrectly parsed (e.g., entire row in one field)."}],"ecosystem":"npm"}