Registry / database / csv-db

csv-db

JSON →
library0.2.2jsnpmunverified

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.

npm install csv-db
INSTALL
IMPORT
SIG · CSV-DB
C
csv-db
databasejavascriptv0.2.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.

CsvDb
const CsvDb = require('csv-db');
import CsvDb from 'csv-db';
The package is CommonJS-only and does not provide ESM exports. Use `require` for module loading.
CsvDb instance
const csvDb = new CsvDb('input.csv', ['id', 'username']);
const csvDb = CsvDb('input.csv', ['id', 'username']);
`CsvDb` is a constructor and must be instantiated with the `new` keyword.

Demonstrates initializing `csv-db` with a file and column names, then fetching all records and a specific record by ID.

const CsvDb = require('csv-db'); const fs = require('fs'); // Create a dummy CSV file for demonstration const filePath = 'example.csv'; const initialData = '1;admin;secret;\n2;user;password;'; fs.writeFileSync(filePath, initialData); const csvDb = new CsvDb(filePath, ['id', 'username', 'password']); csvDb.get().then((data) => { console.log('All data:', data); // Expected output: [{ id: '1', username: 'admin', password: 'secret' }, { id: '2', username: 'user', password: 'password' }] }).catch((err) => { console.error('Error fetching all data:', err); }); csvDb.get('1').then((data) => { console.log('Data for ID 1:', data); // Expected output: [{ id: '1', username: 'admin', password: 'secret' }] }).catch((err) => { console.error('Error fetching data by ID:', err); }); // Clean up the dummy file process.on('exit', () => { if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); console.log(`Cleaned up ${filePath}`); } });
Debug
Known issues
breakingThe 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.
fix
Rewrite data access operations to use Promises (e.g., `.then()`/`.catch()` or `async/await`).
affects: <0.2.0
gotchaThis 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.
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.
affects: >=0.2.2
gotchaAs 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.
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.
affects: >=0.2.0
gotchaThe package uses semicolons (`;`) as the default field separator. Using a comma-separated (`,`) CSV file will result in incorrect parsing.
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.
affects: >=0.2.0
gotchaThe `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.
fix
When updating, first `get` the existing record, merge the changes, then pass the complete merged object to `update`.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: CsvDb is not a constructor
Attempting to use `CsvDb` as a function or importing it incorrectly in an ESM context.
fix
Ensure you are using CommonJS `const CsvDb = require('csv-db');` and instantiating with `new CsvDb(...)`.
Error: ENOENT: no such file or directory, open 'your-file.csv'
The specified CSV file path does not exist or is inaccessible.
fix
Verify the file path is correct and the Node.js process has read/write permissions for the file and directory.
UnhandledPromiseRejectionWarning: Unhandled promise rejection.
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.
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.
Data appears corrupted or incorrectly parsed (e.g., entire row in one field).
The CSV file is not formatted with semicolons (`;`) as field separators, or headers do not match.
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.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
14
OpenAI (training)
1
Resources
csv-db — npm install csv-db · libregistry